-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On on older machine (2.6.16.29 kernel, glibc 3.4.6), when using /proc emulation, openat(fd,"",O_RDONLY) was accidentally succeeding in opening a copy of /proc/self/fd/n (ie. the directory pointed to by fd) instead of failing with ENOENT. Fixed as follows. Fortunately, in a quick audit, I didn't see any code path in fts or coreutils that seems like it would pass an empty argument to openat, which is why my test-openat-safer was the first thing to catch this in nearly 3 years of use.
- -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkqh2voACgkQ84KuGfSFAYBxOQCcD/+S3vNkOQ9VOM1bxqhwwzhV BH4AoMwaMEkZX1Vr2IpVcQkzRlZq3yWU =0dhK -----END PGP SIGNATURE-----
>From c46ae39631773a7fdae7d171cc4ef0bf2123efff Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 4 Sep 2009 21:22:21 -0600 Subject: [PATCH] openat: fail with ENOENT on empty name * lib/openat-proc.c (openat_proc_name): Special-case the empty buffer. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 4 ++++ lib/openat-proc.c | 7 +++++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 193ec7f..ecbf16e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-04 Eric Blake <e...@byu.net> + openat: fail with ENOENT on empty name + * lib/openat-proc.c (openat_proc_name): Special-case the empty + buffer. + link-follow: fix logic bug in prior patch * m4/link-follow.m4 (gl_FUNC_LINK_FOLLOWS_SYMLINK): Fix bug that reversed sense of yes and no in prior patch. Avoid confusing diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 8057033..76e1c6d 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -57,6 +57,13 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) { static int proc_status = 0; + /* Make sure the caller gets ENOENT when appropriate. */ + if (!*file) + { + buf[0] = '\0'; + return buf; + } + if (! proc_status) { /* Set PROC_STATUS to a positive value if /proc/self/fd is -- 1.6.3.3.334.g916e1