From 699ab32b5dbaf44d715aa08aa21d1ec62e479d2b Mon Sep 17 00:00:00 2001 From: richardweinberger Date: Fri, 8 Jan 2021 11:07:02 +0100 Subject: 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 --- util/fusermount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/fusermount.c') 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); -- cgit v1.2.3