Skip to content

Commit

Permalink
qdisc: avoid calling strstr() with a NULL haystack
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Haller <thaller@redhat.com>
  • Loading branch information
Nicolas PLANEL authored and thom311 committed Aug 27, 2014
1 parent 54ae1d9 commit a640e97
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/cli/qdisc/hfsc.c
Expand Up @@ -81,12 +81,13 @@ hfsc_get_sc(char *optarg, struct tc_service_curve *sc)
{
unsigned int m1 = 0, d = 0, m2 = 0;
char *tmp = strdup(optarg);
char *p = tmp, *endptr;
char *p, *endptr;
char *pp = tmp;

if (!tmp)
return -ENOMEM;

p = strstr(p, "m1:");
p = strstr(pp, "m1:");
if (p) {
char *q;
p += 3;
Expand All @@ -99,10 +100,10 @@ hfsc_get_sc(char *optarg, struct tc_service_curve *sc)
m1 = strtoul(p, &endptr, 10);
if (endptr == p)
goto err;
p = q + 1;
}
pp = q + 1;
}

p = strstr(p, "d:");
p = strstr(pp, "d:");
if (p) {
char *q;
p += 2;
Expand All @@ -115,18 +116,18 @@ hfsc_get_sc(char *optarg, struct tc_service_curve *sc)
d = strtoul(p, &endptr, 10);
if (endptr == p)
goto err;
p = q + 1;
}
pp = q + 1;
}

p = strstr(p, "m2:");
p = strstr(pp, "m2:");
if (p) {
p += 3;
if (*p == 0)
goto err;
m2 = strtoul(p, &endptr, 10);
if (endptr == p)
goto err;
} else
} else
goto err;

free(tmp);
Expand Down

0 comments on commit a640e97

Please sign in to comment.