bpo-37138: fix undefined behaviour with memcpy() on NULL array#13867
bpo-37138: fix undefined behaviour with memcpy() on NULL array#13867gpshead merged 1 commit intopython:masterfrom
Conversation
|
@vstinner Would you be able to review this fix, please? Thanks a lot. :) |
|
In any case, I think should be added a test. |
|
I'm not sure an explicit test for this is really needed. (nice to have though) From the bug, this code path was called all the time with the relevant 0 / null based on the undefined behavior sanitizer buildbot output (though I never bothered trying to trace what codepath's triggered it). So this case is covered by something. I'm just not sure explicitly how. If you feel you can add a test that triggers this specific code path, go for it. also, i've added the skip news label as this isn't really worth mentioning in news. its an internal only bugfix for a behavior in beta1 that shouldn't be tripping anyone up in reality. |
|
It occurs for example every time that |
|
In fact, there is already an explicit test in |
Yep: I wrote it because this code path caused troubles in the past ;-) |
| /* use borrowed references */ | ||
| newargs[0] = self; | ||
| memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); | ||
| if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be |
There was a problem hiding this comment.
I don't think that the comment is required.
@gpshead: what do you think?
There was a problem hiding this comment.
I wrote the comment because the reason for that if (totalargs) is totally not obvious. It's an obscure point in the C standard that I was unaware of. I think that there are plenty of developers that do not know that memcpy(dst, NULL, 0) is undefined behaviour.
There was a problem hiding this comment.
I'm in favor of such comments. :)
| /* use borrowed references */ | ||
| newargs[0] = self; | ||
| memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); | ||
| if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be |
There was a problem hiding this comment.
I'm in favor of such comments. :)
…nGH-13867) (cherry picked from commit 1f95317) Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
|
GH-13900 is a backport of this pull request to the 3.8 branch. |
) (cherry picked from commit 1f95317) Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
https://bugs.python.org/issue37138