gh-130052: Fix search_map_for_section() error handling#132594
gh-130052: Fix search_map_for_section() error handling#132594vstinner merged 1 commit intopython:mainfrom
Conversation
* 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. |
|
GH-132598 is a backport of this pull request to the 3.13 branch. |
|
@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 |
Uh oh!
There was an error while loading. Please reload this page.