aboutsummaryrefslogtreecommitdiff
path: root/io/tst-mkdirat.c
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2024-08-22 11:25:14 +0000
committerJoseph Myers <josmyers@redhat.com>2024-08-22 11:25:14 +0000
commit55cd51d971b84fbb2cc0fe8140cc8581f98582c7 (patch)
tree53c3d71c13a88fc5ba68fe4c0633f5fa0f7bc377 /io/tst-mkdirat.c
parent7f04bb4e49413bd57ac3215f3480b09ae7131968 (diff)
downloadglibc-55cd51d971b84fbb2cc0fe8140cc8581f98582c7.zip
glibc-55cd51d971b84fbb2cc0fe8140cc8581f98582c7.tar.gz
glibc-55cd51d971b84fbb2cc0fe8140cc8581f98582c7.tar.bz2
Test mkdirat use of mode argument
The test io/tst-mkdirat doesn't verify the permissions on the created directory (thus, doesn't verify at all anything about how mkdirat uses the mode argument). Add checks of this to the existing test. Tested for x86_64.
Diffstat (limited to 'io/tst-mkdirat.c')
-rw-r--r--io/tst-mkdirat.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/io/tst-mkdirat.c b/io/tst-mkdirat.c
index 605e51e..b97bc3c 100644
--- a/io/tst-mkdirat.c
+++ b/io/tst-mkdirat.c
@@ -53,6 +53,10 @@ prepare (void)
static int
do_test (void)
{
+ /* Find the current umask. */
+ mode_t mask = umask (022);
+ umask (mask);
+
/* fdopendir takes over the descriptor, make a copy. */
int dupfd = dup (dir_fd);
if (dupfd == -1)
@@ -107,6 +111,13 @@ do_test (void)
puts ("mkdirat did not create a directory");
return 1;
}
+ if ((st1.st_mode & 01777) != (~mask & 0777))
+ {
+ printf ("mkdirat created directory with wrong mode %o, expected %o\n",
+ (unsigned int) (st1.st_mode & 01777),
+ (unsigned int) (~mask & 0777));
+ return 1;
+ }
dupfd = dup (dir_fd);
if (dupfd == -1)
@@ -156,6 +167,37 @@ do_test (void)
return 1;
}
+ /* Test again with a different mode. */
+ umask (0);
+ e = mkdirat (dir_fd, "some-dir", 01755);
+ umask (mask);
+ if (e == -1)
+ {
+ puts ("directory creation (different mode) failed");
+ return 1;
+ }
+ if (fstatat64 (dir_fd, "some-dir", &st1, 0) != 0)
+ {
+ puts ("fstat64 (different mode) failed");
+ return 1;
+ }
+ if (!S_ISDIR (st1.st_mode))
+ {
+ puts ("mkdirat (different mode) did not create a directory");
+ return 1;
+ }
+ if ((st1.st_mode & 01777) != 01755)
+ {
+ printf ("mkdirat (different mode) created directory with wrong mode %o\n",
+ (unsigned int) (st1.st_mode & 01777));
+ return 1;
+ }
+ if (unlinkat (dir_fd, "some-dir", AT_REMOVEDIR) != 0)
+ {
+ puts ("unlinkat (different mode) failed");
+ return 1;
+ }
+
close (dir_fd);
return 0;