-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-130052: Fix search_map_for_section() error handling #132594
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
commented
Apr 16, 2025
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Don't call close() if the file descriptor is negative.
- If close() fails, chain the existing exception.
- Issue: Some error paths do not set Exceptions in _testexternalinspection #130052
* Don't call close() if the file descriptor is negative. * If close() fails, chain the existing exception.
Example to trigger #130052 (comment) bug. Apply the patch: diff --git a/Modules/_testexternalinspection.c b/Modules/_testexternalinspection.c
index e90cfb9132b..dfb874c2f9a 100644
--- a/Modules/_testexternalinspection.c
+++ b/Modules/_testexternalinspection.c
@@ -335,6 +335,7 @@ search_map_for_section(pid_t pid, const char* secname, const char* map)
uintptr_t result = 0;
void* file_memory = NULL;
+elf_file[0] = 'X';
int fd = open(elf_file, O_RDONLY);
if (fd < 0) {
PyErr_SetFromErrno(PyExc_OSError); Run the test:
|
LGTM thanks a lot @vstinner |
There is another bug in find_map_start_address(), it fails to retrieve the ELF filename in some cases. But I chose to focus on the first most urgent bug. The bug is hard is reproduce. |
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…H-132594) * Don't call close() if the file descriptor is negative. * If close() fails, chain the existing exception. (cherry picked from commit 014c7f9) Co-authored-by: Victor Stinner <[email protected]>
GH-132598 is a backport of this pull request to the 3.13 branch. |
) (#132598) gh-130052: Fix search_map_for_section() error handling (GH-132594) * Don't call close() if the file descriptor is negative. * If close() fails, chain the existing exception. (cherry picked from commit 014c7f9) Co-authored-by: Victor Stinner <[email protected]>
@vstinner thanks for the fix! Do you want me to look at the second bug? |
If you want. Sometimes, find_map_start_address() fails to parse the ELF filename and so open() fails. For example, the filename starts with spaces and ends with a newline. I don't know how to reproduce the bug in a reliable way. |
It seems that @pablogsal fixed this, at least he handle Lines 524 to 539 in 56c88e4
I tried to reproduce, but
|