From d6095bd826d000e03e6071725a9f0436d3bf3129 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 20 Sep 2011 22:36:37 +0200 Subject: [PATCH] openat tests: EBADF tests. * tests/test-fchownat.c (main): Add tests for EBADF. * tests/test-fstatat.c (main): Likewise. * tests/test-mkdirat.c (main): Likewise. * tests/test-openat.c (main): Likewise. * tests/test-unlinkat.c (main): Likewise. * tests/test-fchmodat.c: New file. * modules/openat-tests (Files): Add tests/test-fchmodat.c. (Makefile.am): Also run 'test-fchmodat'. --- ChangeLog | 12 ++++++++++++ modules/openat-tests | 8 ++++++-- tests/test-fchmodat.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ tests/test-fchownat.c | 12 ++++++++++++ tests/test-fstatat.c | 16 ++++++++++++++++ tests/test-mkdirat.c | 12 ++++++++++++ tests/test-openat.c | 12 ++++++++++++ tests/test-unlinkat.c | 12 ++++++++++++ 8 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 tests/test-fchmodat.c diff --git a/ChangeLog b/ChangeLog index 29048f53c..04668ed25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2011-09-20 Bruno Haible + openat tests: EBADF tests. + * tests/test-fchownat.c (main): Add tests for EBADF. + * tests/test-fstatat.c (main): Likewise. + * tests/test-mkdirat.c (main): Likewise. + * tests/test-openat.c (main): Likewise. + * tests/test-unlinkat.c (main): Likewise. + * tests/test-fchmodat.c: New file. + * modules/openat-tests (Files): Add tests/test-fchmodat.c. + (Makefile.am): Also run 'test-fchmodat'. + +2011-09-20 Bruno Haible + utimens, futimens, fdutimensat tests: EBADF tests. * tests/test-futimens.h (test_futimens): Add more tests for EBADF. diff --git a/modules/openat-tests b/modules/openat-tests index b83fb721d..da00b983f 100644 --- a/modules/openat-tests +++ b/modules/openat-tests @@ -12,6 +12,7 @@ tests/test-fstatat.c tests/test-mkdirat.c tests/test-openat.c tests/test-unlinkat.c +tests/test-fchmodat.c tests/signature.h tests/macros.h @@ -29,8 +30,11 @@ configure.ac: AC_CHECK_FUNCS_ONCE([getegid]) Makefile.am: -TESTS += test-fchownat test-fstatat test-mkdirat test-openat test-unlinkat -check_PROGRAMS += test-fchownat test-fstatat test-mkdirat test-openat \ +TESTS += \ + test-fchmodat test-fchownat test-fstatat test-mkdirat test-openat \ + test-unlinkat +check_PROGRAMS += \ + test-fchmodat test-fchownat test-fstatat test-mkdirat test-openat \ test-unlinkat test_fchownat_LDADD = $(LDADD) @LIBINTL@ test_fstatat_LDADD = $(LDADD) @LIBINTL@ diff --git a/tests/test-fchmodat.c b/tests/test-fchmodat.c new file mode 100644 index 000000000..d52f5c33f --- /dev/null +++ b/tests/test-fchmodat.c @@ -0,0 +1,44 @@ +/* Test changing the protections of a file relative to an open directory. + Copyright (C) 2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (fchmodat, int, (int, const char *, mode_t, int)); + +#include + +#include "macros.h" + +int +main (void) +{ + /* Test behaviour for invalid file descriptors. */ + { + errno = 0; + ASSERT (fchmodat (-1, "foo", 0600, 0) == -1); + ASSERT (errno == EBADF); + } + { + errno = 0; + ASSERT (fchmodat (99, "foo", 0600, 0) == -1); + ASSERT (errno == EBADF); + } + + return 0; +} diff --git a/tests/test-fchownat.c b/tests/test-fchownat.c index 060013e1e..dda6c0fd6 100644 --- a/tests/test-fchownat.c +++ b/tests/test-fchownat.c @@ -69,6 +69,18 @@ main (int argc _GL_UNUSED, char *argv[]) /* Clean up any trash from prior testsuite runs. */ ignore_value (system ("rm -rf " BASE "*")); + /* Test behaviour for invalid file descriptors. */ + { + errno = 0; + ASSERT (fchownat (-1, "foo", getuid (), getgid (), 0) == -1); + ASSERT (errno == EBADF); + } + { + errno = 0; + ASSERT (fchownat (99, "foo", getuid (), getgid (), 0) == -1); + ASSERT (errno == EBADF); + } + /* Basic tests. */ result1 = test_chown (do_chown, true); result2 = test_lchown (do_lchown, result1 == 0); diff --git a/tests/test-fstatat.c b/tests/test-fstatat.c index aef113655..297eb798f 100644 --- a/tests/test-fstatat.c +++ b/tests/test-fstatat.c @@ -67,6 +67,22 @@ main (int argc _GL_UNUSED, char *argv[]) /* Remove any leftovers from a previous partial run. */ ignore_value (system ("rm -rf " BASE "*")); + /* Test behaviour for invalid file descriptors. */ + { + struct stat statbuf; + + errno = 0; + ASSERT (fstatat (-1, "foo", &statbuf, 0) == -1); + ASSERT (errno == EBADF); + } + { + struct stat statbuf; + + errno = 0; + ASSERT (fstatat (99, "foo", &statbuf, 0) == -1); + ASSERT (errno == EBADF); + } + result = test_stat_func (do_stat, false); ASSERT (test_lstat_func (do_lstat, false) == result); dfd = open (".", O_RDONLY); diff --git a/tests/test-mkdirat.c b/tests/test-mkdirat.c index 0eb5e2d49..cd0c6cdf4 100644 --- a/tests/test-mkdirat.c +++ b/tests/test-mkdirat.c @@ -57,6 +57,18 @@ main (int argc _GL_UNUSED, char *argv[]) /* Clean up any trash from prior testsuite runs. */ ignore_value (system ("rm -rf " BASE "*")); + /* Test behaviour for invalid file descriptors. */ + { + errno = 0; + ASSERT (mkdirat (-1, "foo", 0700) == -1); + ASSERT (errno == EBADF); + } + { + errno = 0; + ASSERT (mkdirat (99, "foo", 0700) == -1); + ASSERT (errno == EBADF); + } + /* Test basic mkdir functionality. */ result = test_mkdir (do_mkdir, false); dfd = open (".", O_RDONLY); diff --git a/tests/test-openat.c b/tests/test-openat.c index 6e6ba5b9b..f36145a3a 100644 --- a/tests/test-openat.c +++ b/tests/test-openat.c @@ -65,6 +65,18 @@ main (int argc _GL_UNUSED, char *argv[]) set_program_name (argv[0]); + /* Test behaviour for invalid file descriptors. */ + { + errno = 0; + ASSERT (openat (-1, "foo", O_RDONLY) == -1); + ASSERT (errno == EBADF); + } + { + errno = 0; + ASSERT (openat (99, "foo", O_RDONLY) == -1); + ASSERT (errno == EBADF); + } + /* Basic checks. */ result = test_open (do_open, false); dfd = open (".", O_RDONLY); diff --git a/tests/test-unlinkat.c b/tests/test-unlinkat.c index 30af671a3..7d25b6ede 100644 --- a/tests/test-unlinkat.c +++ b/tests/test-unlinkat.c @@ -68,6 +68,18 @@ main (int argc _GL_UNUSED, char *argv[]) /* Remove any leftovers from a previous partial run. */ ignore_value (system ("rm -rf " BASE "*")); + /* Test behaviour for invalid file descriptors. */ + { + errno = 0; + ASSERT (unlinkat (-1, "foo", 0) == -1); + ASSERT (errno == EBADF); + } + { + errno = 0; + ASSERT (unlinkat (99, "foo", 0) == -1); + ASSERT (errno == EBADF); + } + result1 = test_rmdir_func (rmdirat, false); result2 = test_unlink_func (unlinker, false); ASSERT (result1 == result2); -- 2.11.0