[PATCH] Tests: Create fiels with mode 0666, not 0777 (bug 33171)

Florian Weimer fweimer@redhat.com
Sun Jul 20 10:10:24 GMT 2025


Mode 0777 should be used for directories only because it results
in executable entries (after typical umasks are applied).

This change was created with a code generation tool.

---
 io/tst-ftw-lnk.c            | 2 +-
 posix/tst-spawn-chdir.c     | 4 ++--
 stdio-common/tst-setvbuf2.c | 6 +++---
 stdlib/test-canon.c         | 2 +-
 support/shell-container.c   | 8 ++++----
 support/test-container.c    | 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/io/tst-ftw-lnk.c b/io/tst-ftw-lnk.c
index 88f1926814..4538f35a3a 100644
--- a/io/tst-ftw-lnk.c
+++ b/io/tst-ftw-lnk.c
@@ -217,7 +217,7 @@ do_test (void)
     FAIL_EXIT1 ("symlink link1-bad failed");
   if (symlink ("link2-tgt", "link2-ok") < 0)
     FAIL_EXIT1 ("symlink link2-ok failed");
-  if (open ("link2-tgt", O_RDWR|O_CREAT, 0777) < 0)
+  if (open ("link2-tgt", O_RDWR|O_CREAT, 0666) < 0)
     FAIL_EXIT1 ("create of link2-tgt failed");
 
   /* Now we run the tests.  */
diff --git a/posix/tst-spawn-chdir.c b/posix/tst-spawn-chdir.c
index b97cd3a2d6..1b1323fd6a 100644
--- a/posix/tst-spawn-chdir.c
+++ b/posix/tst-spawn-chdir.c
@@ -156,13 +156,13 @@ do_test (void)
           TEST_COMPARE (posix_spawn_file_actions_addopen
                         (&actions, 3, /* Arbitrary unused descriptor.  */
                          "probe-file",
-                         O_WRONLY | O_CREAT | O_EXCL, 0777), 0);
+                         O_WRONLY | O_CREAT | O_EXCL, 0666), 0);
           TEST_COMPARE (posix_spawn_file_actions_addclose (&actions, 3), 0);
           /* Run the actual in iteration_directory.  */
           add_chdir (&actions, "..", do_fchdir, 5);
           TEST_COMPARE (posix_spawn_file_actions_addopen
                         (&actions, STDOUT_FILENO, "output-file",
-                         O_WRONLY | O_CREAT | O_EXCL, 0777), 0);
+                         O_WRONLY | O_CREAT | O_EXCL, 0666), 0);
 
           /* Check that posix_spawn_file_actions_addchdir_np made a copy
              of the path.  */
diff --git a/stdio-common/tst-setvbuf2.c b/stdio-common/tst-setvbuf2.c
index 84d8b43a58..a31fd2ddff 100644
--- a/stdio-common/tst-setvbuf2.c
+++ b/stdio-common/tst-setvbuf2.c
@@ -265,7 +265,7 @@ writer_thread_proc (void *closure)
   debug;
 
   if (td->fname)
-    td->fd = xopen (td->fname, O_WRONLY, 0777);
+    td->fd = xopen (td->fname, O_WRONLY, 0666);
   fd = td->fd;
 
   while (1)
@@ -292,7 +292,7 @@ reader_thread_proc (void *closure)
   debug;
 
   if (td->fname)
-    td->fd = xopen (td->fname, O_RDONLY, 0777);
+    td->fd = xopen (td->fname, O_RDONLY, 0666);
   fd = td->fd;
 
   while (1)
@@ -538,7 +538,7 @@ open_test_stream (enum test_source_case f, enum test_stream_case s)
       break;
 
     case test_stream_fdopen_w:
-      fd = xopen (fname, O_WRONLY|O_CREAT|O_TRUNC, 0777);
+      fd = xopen (fname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
       fp = fdopen (fd, "w");
       break;
 
diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c
index 51b0af1773..51ac60d412 100644
--- a/stdlib/test-canon.c
+++ b/stdlib/test-canon.c
@@ -165,7 +165,7 @@ do_test (int argc, char ** argv)
 
   int has_dir = mkdir ("doesExist", 0777) == 0;
 
-  int fd = has_dir ? creat ("doesExist/someFile", 0777) : -1;
+  int fd = has_dir ? creat ("doesExist/someFile", 0666) : -1;
 
   for (i = 0; i < (int) (sizeof (tests) / sizeof (tests[0])); ++i)
     {
diff --git a/support/shell-container.c b/support/shell-container.c
index dcf53add07..06f3212488 100644
--- a/support/shell-container.c
+++ b/support/shell-container.c
@@ -237,25 +237,25 @@ run_command_array (char **argv)
     {
       if (strcmp (argv[i], "<") == 0 && argv[i + 1])
 	{
-	  new_stdin = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0777);
+	  new_stdin = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0666);
 	  ++i;
 	  continue;
 	}
       if (strcmp (argv[i], ">") == 0 && argv[i + 1])
 	{
-	  new_stdout = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0777);
+	  new_stdout = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0666);
 	  ++i;
 	  continue;
 	}
       if (strcmp (argv[i], ">>") == 0 && argv[i + 1])
 	{
-	  new_stdout = open (argv[i + 1], O_WRONLY|O_CREAT|O_APPEND, 0777);
+	  new_stdout = open (argv[i + 1], O_WRONLY|O_CREAT|O_APPEND, 0666);
 	  ++i;
 	  continue;
 	}
       if (strcmp (argv[i], "2>") == 0 && argv[i + 1])
 	{
-	  new_stderr = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0777);
+	  new_stderr = open (argv[i + 1], O_WRONLY|O_CREAT|O_TRUNC, 0666);
 	  ++i;
 	  continue;
 	}
diff --git a/support/test-container.c b/support/test-container.c
index 1c40ab377f..ae643d307e 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -273,7 +273,7 @@ devmount (const char *new_root_path, const char *which)
 {
   int fd;
   fd = open (concat (new_root_path, "/dev/", which, NULL),
-	     O_CREAT | O_TRUNC | O_RDWR, 0777);
+	     O_CREAT | O_TRUNC | O_RDWR, 0666);
   xclose (fd);
 
   trymount (concat ("/dev/", which, NULL),

base-commit: 8cab264b26411579051de930417ca4a346e0254c



More information about the Libc-alpha mailing list