Fix a few potential NULL dereferences
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 20 Sep 2024 11:33:38 +0000 (21:33 +1000)
committerMarge Bot <emma+marge@anholt.net>
Mon, 30 Sep 2024 15:35:36 +0000 (15:35 +0000)
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1052>

src/util-strings.h
test/test-utils.c
tools/shared.c

index bc263f6c9a31775bda45ded1ef55da735b0faaf4..ee463dc69979d8bee6b18ed5d855e2656f577f96 100644 (file)
@@ -419,7 +419,7 @@ strstrip(const char *input, const char *what)
 
        last = str;
 
-       for (char *c = str; *c != '\0'; c++) {
+       for (char *c = str; c && *c != '\0'; c++) {
                if (!strchr(what, *c))
                        last = c + 1;
        }
index ee9cc606aa0d569119906e889e75b871ab4b8f3e..d1b7345a42b6d99e660f0f521037e416a8e4d101 100644 (file)
@@ -1218,8 +1218,10 @@ START_TEST(double_array_from_string_test)
                                                         &len);
                ck_assert_int_eq(len, t->len);
 
-               for (size_t idx = 0; idx < len; idx++)
+               for (size_t idx = 0; idx < len; idx++) {
+                       ck_assert_ptr_nonnull(array);
                        ck_assert_double_eq(array[idx], t->array[idx]);
+               }
 
                free(array);
                t++;
index 58a428f8d35c4cef96df2eb2aeeb47428e747b4e..06f027c1fbf4695c7aed94dfc492aadfa077e557 100644 (file)
@@ -360,7 +360,7 @@ tools_parse_option(int option,
 
                size_t npoints = 0;
                double *range = double_array_from_string(optarg, ":", &npoints);
-               if (npoints != 2 || range[0] < 0.0 || range[1] > 1.0 || range[0] >= range[1]) {
+               if (npoints != 2 || !range || range[0] < 0.0 || range[1] > 1.0 || range[0] >= range[1]) {
                        free(range);
                        fprintf(stderr, "Invalid pressure range, must be in format \"min:max\"\n");
                        return 1;
@@ -376,7 +376,7 @@ tools_parse_option(int option,
 
                size_t npoints = 0;
                double *matrix = double_array_from_string(optarg, " ", &npoints);
-               if (npoints != 6) {
+               if (!matrix || npoints != 6) {
                        free(matrix);
                        fprintf(stderr, "Invalid calibration matrix, must be 6 space-separated values\n");
                        return 1;