-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
lib: fix a Null Pointer Dereference bug. #18066
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: mugitya03 <[email protected]>
@Mergifyio backport dev/10.3 stable/10.2 stable/10.1 stable/10.0 |
🟠 Waiting for conditions to match
|
@@ -693,7 +693,8 @@ static PyObject *elffile_secbyidx(struct elffile *w, Elf_Scn *scn, size_t idx) | |||
} | |||
|
|||
ret = w->sects[idx]; | |||
Py_INCREF(ret); | |||
if (ret) | |||
Py_INCREF(ret); |
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'd rather replace to Py_XINCREF
all the occurrences.
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.
Yes, Py_XINCREF first checks for a null value. I'll submit a new PR replacing the API.
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.
This is actually not correct as CPython functions are not allowed to return NULL without setting an error. This change coverts a guaranteed crash into indeterminate Python behavior.
This work is completely irrelevant since this code is only executed at build time in a controlled environment. |
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 going to just NAK this since this is a build-time only tool and if we run out of memory here the build has failed anyway. Considering how memory allocation works, the failure behavior is not sane in any case as the build will start paging and swapping before this happens. Whether we ultimately crash with a SEGV or something nicer is… academic.
The function
elfsect_wrap
can return a NULL value when allocation fails at line 573.The null value returned by function
elfsect_wrap
is saved tow->sects[idx]
and further assigned to pointerret
. Then the pointerptr
is passed to functionPy_INCREF
at line , where it can be dereferenced.The definition of function
Py_INCREF
can be found here: linkThus, we add a null value check before calling the function
Py_INCREF
.