From: Tobias Stoeckmann Date: Tue, 18 Feb 2025 21:40:40 +0000 (+0100) Subject: static-nodes: do not open /dev/stdout explicitly X-Git-Tag: v34~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ae5179d4880344f4a0680eb15001003491082ef;p=thirdparty%2Fkmod.git static-nodes: do not open /dev/stdout explicitly 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 Link: https://github.com/kmod-project/kmod/pull/283 Signed-off-by: Lucas De Marchi --- diff --git a/tools/static-nodes.c b/tools/static-nodes.c index 0ecb9030..f4eeeb69 100644 --- a/tools/static-nodes.c +++ b/tools/static-nodes.c @@ -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) {