Repository navigation
gh-151633: avoid use-after-free in Counter.update - #151634
KowalskiThomas wants to merge 15 commits into
Conversation
|
Thanks for the review, I'll take a look ASAP. |
| int found; | ||
| int cs_err = 0; | ||
| PyObject *newval = NULL; | ||
| Py_BEGIN_CRITICAL_SECTION(mapping); |
There was a problem hiding this comment.
The current PR looks good, but I think we can improve a bit more. The locking via the critical section now happens on each iteration, which seems a bit of a waste.
Can we place the critical section outside the while loop and then extract most (all?) of the code into a method _count_elements_dict_lock_held?
There was a problem hiding this comment.
I'll look into this as soon as possible, thanks for reporting.
There was a problem hiding this comment.
@eendebakpt Sorry, I completely forgot about that for some reason... I just changed it to do what you proposed, let me know how that looks!
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
192fc9f to
c34c4a2
Compare
|
Sorry in advance, I had to rebase on main (instead of merge) because Git wouldn't let me "merge unrelated histories"... Not sure what happened there... |
…use-after-free-in-counter-update
|
Just merged |
eendebakpt
left a comment
There was a problem hiding this comment.
Thanks @KowalskiThomas. I added one minor change (also to retrigger the CI), but looks good. Performance for large updates is also improved with these changes, which is a nice side effect.
Fixes #151633.
Counter.updatecan cause a use after free #151633