-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-37138: fix undefined behaviour with memcpy() on NULL array #13867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, the code change makes sense. I'm not clicking merge for now in case @jdemeyer wants to add an explicit test. I'll leave that up to Jeroen.
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 ;-) |
@@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args, | |||
} | |||
/* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the comment is required.
@gpshead: what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of such comments. :)
@@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args, | |||
} | |||
/* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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