From: Colin Ian King Date: Thu, 2 Jun 2016 18:25:54 +0000 (+0100) Subject: Fix null pointer dereference on strlen() X-Git-Tag: v0.8~42^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=248f41fc82e85e3722084c54d900b4fc36a34081;p=users%2Fsagi%2Fnvme-cli.git Fix null pointer dereference on strlen() 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 --- diff --git a/src/argconfig.c b/src/argconfig.c index b7aa86ce..b5447fa6 100644 --- a/src/argconfig.c +++ b/src/argconfig.c @@ -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, ",");