mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-27 03:33:33 +08:00
* sysdeps/unix/sysv/linux/renameat.c (__atfct_seterrno_2): Correcty
return EBADF for non-existing file descriptors. * sysdeps/unix/sysv/linux/openat.c (__atfct_seterrno): Likewise. * io/tst-openat.c (do_test): Add some more tests. * io/tst-faccessat.c (do_test): Likewise. * io/tst-renameat.c (do_test): Likewise. * io/tst-fstatat.c (do_test): Likewise. * io/tst-fchmodat.c (do_test): Likewise. * io/tst-fchownat.c (do_test): Likewise.
This commit is contained in:
parent
b2680b0331
commit
bdc7e223aa
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2006-01-21 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* sysdeps/unix/sysv/linux/renameat.c (__atfct_seterrno_2): Correcty
|
||||
return EBADF for non-existing file descriptors.
|
||||
* sysdeps/unix/sysv/linux/openat.c (__atfct_seterrno): Likewise.
|
||||
* io/tst-openat.c (do_test): Add some more tests.
|
||||
* io/tst-faccessat.c (do_test): Likewise.
|
||||
* io/tst-renameat.c (do_test): Likewise.
|
||||
* io/tst-fstatat.c (do_test): Likewise.
|
||||
* io/tst-fchmodat.c (do_test): Likewise.
|
||||
* io/tst-fchownat.c (do_test): Likewise.
|
||||
|
||||
2006-01-21 Roland McGrath <roland@redhat.com>
|
||||
|
||||
* sysdeps/unix/sysv/linux/faccessat.c: Move RESULT defn inside block.
|
||||
|
@ -98,6 +98,20 @@ do_test (void)
|
||||
write (fd, "hello", 5);
|
||||
puts ("file created");
|
||||
|
||||
/* Before closing the file, try using this file descriptor to open
|
||||
another file. This must fail. */
|
||||
if (faccessat (fd, "should-not-work", F_OK, AT_EACCESS) != -1)
|
||||
{
|
||||
puts ("faccessat using descriptor for normal file worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("\
|
||||
error for faccessat using descriptor for normal file not ENOTDIR ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
int result = 0;
|
||||
@ -141,6 +155,39 @@ do_test (void)
|
||||
result = 1;
|
||||
}
|
||||
|
||||
/* Create a file descriptor which is closed again right away. */
|
||||
int dir_fd2 = dup (dir_fd);
|
||||
if (dir_fd2 == -1)
|
||||
{
|
||||
puts ("dup failed");
|
||||
return 1;
|
||||
}
|
||||
close (dir_fd2);
|
||||
|
||||
/* With the file descriptor closed the next call must fail. */
|
||||
if (faccessat (dir_fd2, "some-file", F_OK, AT_EACCESS) != -1)
|
||||
{
|
||||
puts ("faccessat using closed descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("faccessat using closed descriptor did not set EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Same with a non-existing file. */
|
||||
if (faccessat (dir_fd2, "non-existing-file", F_OK, AT_EACCESS) != -1)
|
||||
{
|
||||
puts ("2nd faccessat using closed descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("2nd faccessat using closed descriptor did not set EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unlinkat (dir_fd, "some-file", 0) != 0)
|
||||
{
|
||||
puts ("unlinkat failed");
|
||||
@ -149,5 +196,17 @@ do_test (void)
|
||||
|
||||
close (dir_fd);
|
||||
|
||||
fd = faccessat (-1, "some-file", F_OK, AT_EACCESS);
|
||||
if (fd != -1)
|
||||
{
|
||||
puts ("faccessat using -1 descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("faccessat using -1 descriptor did not set EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -107,6 +107,20 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Before closing the file, try using this file descriptor to open
|
||||
another file. This must fail. */
|
||||
if (fchmodat (fd, "some-file", 0400, 0) != -1)
|
||||
{
|
||||
puts ("fchmodat using descriptor for normal file worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("\
|
||||
error for fchmodat using descriptor for normal file not ENOTDIR ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
if ((st1.st_mode & 0777) != 0644)
|
||||
@ -140,7 +154,38 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create a file descriptor which is closed again right away. */
|
||||
int dir_fd2 = dup (dir_fd);
|
||||
if (dir_fd2 == -1)
|
||||
{
|
||||
puts ("dup failed");
|
||||
return 1;
|
||||
}
|
||||
close (dir_fd2);
|
||||
|
||||
if (fchmodat (dir_fd2, "some-file", 0400, 0) != -1)
|
||||
{
|
||||
puts ("fchmodat using closed descriptor worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for fchmodat using closed descriptor not EBADF ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (dir_fd);
|
||||
|
||||
if (fchmodat (-1, "some-file", 0400, 0) != -1)
|
||||
{
|
||||
puts ("fchmodat using invalid descriptor worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for fchmodat using invalid descriptor not EBADF ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -112,6 +112,20 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Before closing the file, try using this file descriptor to open
|
||||
another file. This must fail. */
|
||||
if (fchownat (fd, "some-file", 1, 1, 0) != -1)
|
||||
{
|
||||
puts ("fchownat using descriptor for normal file worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("\
|
||||
error for fchownat using descriptor for normal file not ENOTDIR ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
if (fchownat (dir_fd, "some-file", st1.st_uid + 1, st1.st_gid + 1, 0) != 0)
|
||||
@ -139,7 +153,38 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create a file descriptor which is closed again right away. */
|
||||
int dir_fd2 = dup (dir_fd);
|
||||
if (dir_fd2 == -1)
|
||||
{
|
||||
puts ("dup failed");
|
||||
return 1;
|
||||
}
|
||||
close (dir_fd2);
|
||||
|
||||
if (fchownat (dir_fd2, "some-file", 1, 1, 0) != -1)
|
||||
{
|
||||
puts ("fchownat using closed descriptor worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for fchownat using closed descriptor not EBADF ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (dir_fd);
|
||||
|
||||
if (fchownat (-1, "some-file", 1, 1, 0) != -1)
|
||||
{
|
||||
puts ("fchownat using invalid descriptor worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for fchownat using invalid descriptor not EBADF ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -97,6 +97,20 @@ do_test (void)
|
||||
puts ("file created");
|
||||
|
||||
struct stat64 st1;
|
||||
|
||||
/* Before closing the file, try using this file descriptor to open
|
||||
another file. This must fail. */
|
||||
if (fstatat64 (fd, "some-file", &st1, 0) != -1)
|
||||
{
|
||||
puts ("fstatatat using descriptor for normal file worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("error for fstatat using descriptor for normal file not ENOTDIR ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fstat64 (fd, &st1) != 0)
|
||||
{
|
||||
puts ("fstat64 failed");
|
||||
@ -137,7 +151,38 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create a file descriptor which is closed again right away. */
|
||||
int dir_fd2 = dup (dir_fd);
|
||||
if (dir_fd2 == -1)
|
||||
{
|
||||
puts ("dup failed");
|
||||
return 1;
|
||||
}
|
||||
close (dir_fd2);
|
||||
|
||||
if (fstatat64 (dir_fd2, "some-file", &st1, 0) != -1)
|
||||
{
|
||||
puts ("fstatat64 using closed descriptor worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for fstatat using closed descriptor not EBADF ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (dir_fd);
|
||||
|
||||
if (fstatat64 (-1, "some-file", &st1, 0) != -1)
|
||||
{
|
||||
puts ("fstatat64 using invalid descriptor worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for fstatat using invalid descriptor not EBADF ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -94,6 +94,21 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
write (fd, "hello", 5);
|
||||
|
||||
/* Before closing the file, try using this file descriptor to open
|
||||
another file. This must fail. */
|
||||
int fd2 = openat (fd, "should-not-work", O_CREAT|O_RDWR, 0666);
|
||||
if (fd2 != -1)
|
||||
{
|
||||
puts ("openat using descriptor for normal file worked");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("error for openat using descriptor for normal file not ENOTDIR ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
puts ("file created");
|
||||
|
||||
@ -165,5 +180,30 @@ do_test (void)
|
||||
close (dir_fd);
|
||||
close (cwdfd);
|
||||
|
||||
/* With the file descriptor closed the next call must fail. */
|
||||
fd = openat (dir_fd, "some-file", O_CREAT|O_RDWR|O_EXCL, 0666);
|
||||
if (fd != -1)
|
||||
{
|
||||
puts ("openat using closed descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("openat using closed descriptor did not set EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd = openat (-1, "some-file", O_CREAT|O_RDWR|O_EXCL, 0666);
|
||||
if (fd != -1)
|
||||
{
|
||||
puts ("openat using -1 descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("openat using -1 descriptor did not set EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,6 +103,29 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Using a descriptor for a normal file must fail. */
|
||||
if (renameat (fd, "some-file", dir_fd, "another-file") == 0)
|
||||
{
|
||||
puts ("renameat with normal file descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("error for renameat with normal file descriptor not ENOTDIR");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (renameat (dir_fd, "some-file", fd, "another-file") == 0)
|
||||
{
|
||||
puts ("2nd renameat with normal file descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != ENOTDIR)
|
||||
{
|
||||
puts ("error for 2nd renameat with normal file descriptor not ENOTDIR");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
if (renameat (dir_fd, "some-file", dir_fd, "another-file") != 0)
|
||||
@ -137,12 +160,65 @@ do_test (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create a file descriptor which is closed again right away. */
|
||||
int dir_fd2 = dup (dir_fd);
|
||||
if (dir_fd2 == -1)
|
||||
{
|
||||
puts ("dup failed");
|
||||
return 1;
|
||||
}
|
||||
close (dir_fd2);
|
||||
|
||||
if (renameat (dir_fd2, "another-file", dir_fd, "some-file") == 0)
|
||||
{
|
||||
puts ("renameat with closed file descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for renameat with closed file descriptor not EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (renameat (dir_fd, "another-file", dir_fd2, "some-file") == 0)
|
||||
{
|
||||
puts ("2nd renameat with closed file descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for 2nd renameat with closed file descriptor not EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unlinkat (dir_fd, "another-file", 0) != 0)
|
||||
{
|
||||
puts ("unlinkat failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (renameat (-1, "another-file", dir_fd, "some-file") == 0)
|
||||
{
|
||||
puts ("renameat with invalid file descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for renameat with invalid file descriptor not EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (renameat (dir_fd, "another-file", -1, "some-file") == 0)
|
||||
{
|
||||
puts ("2nd renameat with invalid file descriptor succeeded");
|
||||
return 1;
|
||||
}
|
||||
if (errno != EBADF)
|
||||
{
|
||||
puts ("error for 2nd renameat with invalid file descriptor not EBADF");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (dir_fd);
|
||||
|
||||
return 0;
|
||||
|
@ -60,7 +60,7 @@ __atfct_seterrno (int errval, int fd, const char *buf)
|
||||
file descriptor number. */
|
||||
*(char *) strchr (buf + sizeof "/proc/self/fd", '/') = '\0';
|
||||
|
||||
int e = __xstat64 (_STAT_VER, buf, &st);
|
||||
int e = __lxstat64 (_STAT_VER, buf, &st);
|
||||
if ((e == -1 && errno == ENOENT)
|
||||
||(e == 0 && !S_ISLNK (st.st_mode)))
|
||||
errval = EBADF;
|
||||
|
@ -30,12 +30,14 @@ attribute_hidden
|
||||
__atfct_seterrno_2 (int errval, int fd1, const char *buf1, int fd2,
|
||||
const char *buf2)
|
||||
{
|
||||
if (errval == ENOTDIR && (buf1 != NULL || buf2 != NULL))
|
||||
if (buf1 != NULL || buf2 != NULL)
|
||||
{
|
||||
struct stat64 st;
|
||||
|
||||
if (errval == ENOTDIR)
|
||||
{
|
||||
/* This can mean either the file descriptor is invalid or
|
||||
/proc is not mounted. */
|
||||
struct stat64 st;
|
||||
|
||||
if (buf1 != NULL)
|
||||
{
|
||||
if (__fxstat64 (_STAT_VER, fd1, &st) != 0)
|
||||
@ -65,6 +67,35 @@ __atfct_seterrno_2 (int errval, int fd1, const char *buf1, int fd2,
|
||||
errval = ENOSYS;
|
||||
}
|
||||
}
|
||||
else if (errval == ENOENT)
|
||||
{
|
||||
/* This could mean the file descriptor is not valid. We
|
||||
reuse BUF for the stat call. Find the slash after the
|
||||
file descriptor number. */
|
||||
if (buf1 != NULL)
|
||||
{
|
||||
*(char *) strchr (buf1 + sizeof "/proc/self/fd", '/') = '\0';
|
||||
|
||||
int e = __lxstat64 (_STAT_VER, buf1, &st);
|
||||
if ((e == -1 && errno == ENOENT)
|
||||
||(e == 0 && !S_ISLNK (st.st_mode)))
|
||||
{
|
||||
errval = EBADF;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (buf2 != NULL)
|
||||
{
|
||||
*(char *) strchr (buf2 + sizeof "/proc/self/fd", '/') = '\0';
|
||||
|
||||
int e = __lxstat64 (_STAT_VER, buf2, &st);
|
||||
if ((e == -1 && errno == ENOENT)
|
||||
||(e == 0 && !S_ISLNK (st.st_mode)))
|
||||
errval = EBADF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
__set_errno (errval);
|
||||
|
Loading…
Reference in New Issue
Block a user