]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
static-nodes: do not open /dev/stdout explicitly
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 18 Feb 2025 21:40:40 +0000 (22:40 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 18 Feb 2025 21:57:37 +0000 (15:57 -0600)
If no -o option is given, use stdout directly without opening
/dev/stdout manually. In a chroot environment, this could lead
to /dev/stdout creation as a regular file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/283
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/static-nodes.c

index 0ecb9030aa6293c167fbd2f8d50e90600b6758b8..f4eeeb69ba60f0c406f56a216d7b9527c74d6bfc 100644 (file)
@@ -145,7 +145,7 @@ static int do_static_nodes(int argc, char *argv[])
 {
        struct utsname kernel;
        char modules[PATH_MAX], buf[PATH_MAX];
-       const char *output = "/dev/stdout";
+       const char *output = NULL;
        FILE *in = NULL, *out = NULL;
        const struct static_nodes_format *format = &static_nodes_format_human;
        int r, ret = EXIT_SUCCESS;
@@ -227,19 +227,24 @@ static int do_static_nodes(int argc, char *argv[])
                goto finish;
        }
 
-       r = mkdir_parents(output, 0755);
-       if (r < 0) {
-               fprintf(stderr, "Error: could not create parent directory for %s - %m.\n",
-                       output);
-               ret = EXIT_FAILURE;
-               goto finish;
-       }
+       if (output == NULL) {
+               out = stdout;
+       } else {
+               r = mkdir_parents(output, 0755);
+               if (r < 0) {
+                       fprintf(stderr,
+                               "Error: could not create parent directory for %s - %m.\n",
+                               output);
+                       ret = EXIT_FAILURE;
+                       goto finish;
+               }
 
-       out = fopen(output, "we");
-       if (out == NULL) {
-               fprintf(stderr, "Error: could not create %s - %m\n", output);
-               ret = EXIT_FAILURE;
-               goto finish;
+               out = fopen(output, "we");
+               if (out == NULL) {
+                       fprintf(stderr, "Error: could not create %s - %m\n", output);
+                       ret = EXIT_FAILURE;
+                       goto finish;
+               }
        }
 
        while (fgets(buf, sizeof(buf), in) != NULL) {