]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Fix null pointer dereference on strlen()
authorColin Ian King <colin.king@canonical.com>
Thu, 2 Jun 2016 18:25:54 +0000 (19:25 +0100)
committerColin Ian King <colin.king@canonical.com>
Thu, 2 Jun 2016 18:25:54 +0000 (19:25 +0100)
If string is NULL, then the proceeding strlen() on the string
will lead to a NULL pointer dereference error (segmentation fault).
Fix this by swapping the order of the comparisons, first check for
a NULL pointer; if that's not true then do the strlen check.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
src/argconfig.c

index b7aa86ce53b8bf3fbb4773253b1bb6711f5f9717..b5447fa6820eb6a8c3ecf4d9ebb53c05da600963 100644 (file)
@@ -364,7 +364,7 @@ int argconfig_parse_subopt_string(char *string, char **options,
        char **o = options;
        char *tmp;
 
-       if (!strlen(string) || string == NULL) {
+       if (!string || !strlen(string)) {
                *(o++) = NULL;
                *(o++) = NULL;
                return 0;
@@ -439,7 +439,7 @@ unsigned argconfig_parse_comma_sep_array(char *string, int *val,
        char *tmp;
        char *p;
 
-       if (!strlen(string) || string == NULL)
+       if (!string || !strlen(string))
                return 0;
 
        tmp = strtok(string, ",");
@@ -480,7 +480,7 @@ unsigned argconfig_parse_comma_sep_array_long(char *string,
        char *tmp;
        char *p;
 
-       if (!strlen(string) || string == NULL)
+       if (!string || !strlen(string))
                return 0;
 
        tmp = strtok(string, ",");