The current cpulist_parse() function ignores extra non-parsable characters at the end of the to be parsed cpu list string. E.g. it would accept something like "0bla" and just set bit 0 in the cpu set. Since such a string is invalid implement stricter parsing that makes sure that everything of the string has been succesfully parsed. Signed-off-by: Heiko Carstens <heiko.carstens@xxxxxxxxxx> --- lib/cpuset.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/cpuset.c b/lib/cpuset.c index 8592755..ebaffcc 100644 --- a/lib/cpuset.c +++ b/lib/cpuset.c @@ -268,8 +268,9 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail) { size_t max = cpuset_nbits(setsize); const char *p, *q; - q = str; + int r; + q = str; CPU_ZERO_S(setsize, set); while (p = q, q = nexttoken(q, ','), p) { @@ -277,8 +278,9 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail) unsigned int b; /* end of range */ unsigned int s; /* stride */ const char *c1, *c2; + char c; - if (sscanf(p, "%u", &a) < 1) + if ((r = sscanf(p, "%u%c", &a, &c)) < 1) return 1; b = a; s = 1; @@ -286,11 +288,11 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail) c1 = nexttoken(p, '-'); c2 = nexttoken(p, ','); if (c1 != NULL && (c2 == NULL || c1 < c2)) { - if (sscanf(c1, "%u", &b) < 1) + if ((r = sscanf(c1, "%u%c", &b, &c)) < 1) return 1; c1 = nexttoken(c1, ':'); if (c1 != NULL && (c2 == NULL || c1 < c2)) { - if (sscanf(c1, "%u", &s) < 1) + if ((r = sscanf(c1, "%u%c", &s, &c)) < 1) return 1; if (s == 0) return 1; @@ -307,6 +309,8 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail) } } + if (r == 2) + return 1; return 0; } -- 1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html