]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(dracut-util): do not call `strcmp` if the `value` argument is NULL
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Mon, 12 Feb 2024 12:55:20 +0000 (13:55 +0100)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Sun, 31 Mar 2024 20:30:37 +0000 (16:30 -0400)
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`.

src/util/util.c

index b3498df6cd84b9b1834ef599e3aa09a40efbe600..1d152418d91e73bfa9e21f709688ac20590e361d 100644 (file)
@@ -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;
                                 }