Commit b394c1da authored by Gregory P. Smith's avatar Gregory P. Smith

Fixes Issue #16962: Use getdents64 instead of the obsolete getdents syscall

in the subprocess module on Linux.
parents 04a29554 255bf5b9
...@@ -273,6 +273,9 @@ Core and Builtins ...@@ -273,6 +273,9 @@ Core and Builtins
Library Library
------- -------
- Issue #16962: Use getdents64 instead of the obsolete getdents syscall
in the subprocess module on Linux.
- Issue #16935: unittest now counts the module as skipped if it raises SkipTest, - Issue #16935: unittest now counts the module as skipped if it raises SkipTest,
instead of counting it as an error. Patch by Zachary Ware. instead of counting it as an error. Patch by Zachary Ware.
......
...@@ -176,17 +176,11 @@ _close_fds_by_brute_force(int start_fd, int end_fd, PyObject *py_fds_to_keep) ...@@ -176,17 +176,11 @@ _close_fds_by_brute_force(int start_fd, int end_fd, PyObject *py_fds_to_keep)
* This structure is very old and stable: It will not change unless the kernel * This structure is very old and stable: It will not change unless the kernel
* chooses to break compatibility with all existing binaries. Highly Unlikely. * chooses to break compatibility with all existing binaries. Highly Unlikely.
*/ */
struct linux_dirent { struct linux_dirent64 {
#if defined(__x86_64__) && defined(__ILP32__)
/* Support the wacky x32 ABI (fake 32-bit userspace speaking to x86_64
* kernel interfaces) - https://sites.google.com/site/x32abi/ */
unsigned long long d_ino; unsigned long long d_ino;
unsigned long long d_off; long long d_off;
#else
unsigned long d_ino; /* Inode number */
unsigned long d_off; /* Offset to next linux_dirent */
#endif
unsigned short d_reclen; /* Length of this linux_dirent */ unsigned short d_reclen; /* Length of this linux_dirent */
unsigned char d_type;
char d_name[256]; /* Filename (null-terminated) */ char d_name[256]; /* Filename (null-terminated) */
}; };
...@@ -228,16 +222,16 @@ _close_open_fd_range_safe(int start_fd, int end_fd, PyObject* py_fds_to_keep) ...@@ -228,16 +222,16 @@ _close_open_fd_range_safe(int start_fd, int end_fd, PyObject* py_fds_to_keep)
_close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep); _close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep);
return; return;
} else { } else {
char buffer[sizeof(struct linux_dirent)]; char buffer[sizeof(struct linux_dirent64)];
int bytes; int bytes;
while ((bytes = syscall(SYS_getdents, fd_dir_fd, while ((bytes = syscall(SYS_getdents64, fd_dir_fd,
(struct linux_dirent *)buffer, (struct linux_dirent64 *)buffer,
sizeof(buffer))) > 0) { sizeof(buffer))) > 0) {
struct linux_dirent *entry; struct linux_dirent64 *entry;
int offset; int offset;
for (offset = 0; offset < bytes; offset += entry->d_reclen) { for (offset = 0; offset < bytes; offset += entry->d_reclen) {
int fd; int fd;
entry = (struct linux_dirent *)(buffer + offset); entry = (struct linux_dirent64 *)(buffer + offset);
if ((fd = _pos_int_from_ascii(entry->d_name)) < 0) if ((fd = _pos_int_from_ascii(entry->d_name)) < 0)
continue; /* Not a number. */ continue; /* Not a number. */
if (fd != fd_dir_fd && fd >= start_fd && fd < end_fd && if (fd != fd_dir_fd && fd >= start_fd && fd < end_fd &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment