From: Antonio Alvarez Feijoo Date: Mon, 12 Feb 2024 12:55:20 +0000 (+0100) Subject: fix(dracut-util): do not call `strcmp` if the `value` argument is NULL X-Git-Tag: 100~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5fb6e049e1fcb465f9371cefeedcfecce7a8d53;p=thirdparty%2Fdracut-ng.git fix(dracut-util): do not call `strcmp` if the `value` argument is NULL The behavior of `strcmp` is undefined if any of its arguments is NULL, which can lead to a segfault depending on the implementation. So, this check is required to be able to use `getargs` with options where the value is optional, e.g., with `rd.break`. --- diff --git a/src/util/util.c b/src/util/util.c index b3498df6c..1d152418d 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -273,7 +273,7 @@ static int getargs(int argc, char **argv) cmdline = next_arg(cmdline, &key, &value); if (strcmp(key, search_key) == 0) { if (search_value) { - if (strcmp(value, search_value) == 0) { + if (value && strcmp(value, search_value) == 0) { printf("%s\n", value); found_value = true; }