From: richardweinberger Date: Fri, 8 Jan 2021 10:07:02 +0000 (+0100) Subject: fusermount: Check for argv[0] being present (#577) X-Git-Tag: fuse-3.10.2~6 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=699ab32b5dbaf44d715aa08aa21d1ec62e479d2b;p=qemu-gpiodev%2Flibfuse.git fusermount: Check for argv[0] being present (#577) It is perfectly legal to execute a program with argc == 0 and therefore no argv. fusermount needs to check for this case, otherwise it will pass a NULL poiunter to strdup() and cause undefined behavior. Especially since fusermount is setuid root, we need to extra be careful. Signed-off-by: Richard Weinberger --- diff --git a/util/fusermount.c b/util/fusermount.c index 45e96bc..243d25e 100644 --- a/util/fusermount.c +++ b/util/fusermount.c @@ -1270,7 +1270,7 @@ int main(int argc, char *argv[]) {"version", no_argument, NULL, 'V'}, {0, 0, 0, 0}}; - progname = strdup(argv[0]); + progname = strdup(argc > 0 ? argv[0] : "fusermount"); if (progname == NULL) { fprintf(stderr, "%s: failed to allocate memory\n", argv[0]); exit(1);