Igor Todorovski wrote: > This was the symptom we experienced with findutils (guarding the close in > gnulib fixed it): > find . -name "test" > The output is: > find: '.': EDC5113I Bad file descriptor. > > https://github.com/ZOSOpenTools/findutilsport/issues/4 > > We’ll do some more testing to see if there’s a better solution.
I'm sending you a testdir, generated through ./gnulib-tool --create-testdir --dir=/tmp/testdir --single-configure \ areadlinkat areadlinkat-with-size faccessat fchmodat fchownat fdopendir getcwd fstatat linkat mkdirat mkfifoat openat readlinkat renameatu savedir symlinkat unlinkat utimensat As part of your testing, please run it through ./configure && make && make check (Sent via private mail, as it's too large for this mailing list.) > __e2a_l is documented here: > https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-e2a-l-convert-characters-from-ebcdic-ascii Well, according to this documentation your patch was buggy: it did not check the return value. Additionally, it ran a conversion on a buffer full of uninitialized data (which is 1. slow and 2. triggers warnings in tools like valgrind). And when w_ioctl failed, your code was accessing and returning unitialized data in dir[]. Ouch ouch ouch. Fixing it like this: 2023-01-30 Bruno Haible <br...@clisp.org> at-internal: Fix support for z/OS. * lib/openat-proc.c (openat_proc_name) [z/OS]: Proper error handling. Convert only the relevant part of the dir[] buffer. diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 6419a8cf5f..88f70be4f5 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -123,8 +123,16 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) # endif # ifdef __MVS__ char dir[_XOPEN_PATH_MAX]; - if (w_ioctl (fd, _IOCC_GPN, sizeof dir, dir) == 0) - __e2a_l (dir, sizeof dir); + /* Documentation: + https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-w-ioctl-w-pioctl-control-devices */ + if (w_ioctl (fd, _IOCC_GPN, sizeof dir, dir) < 0) + return NULL; + /* Documentation: + https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-e2a-l-convert-characters-from-ebcdic-ascii */ + dirlen = __e2a_l (dir, strlen (dir)); + if (dirlen < 0 || dirlen >= sizeof dir) + return NULL; + dir[dirlen] = '\0'; # endif dirlen = strlen (dir);