summaryrefslogtreecommitdiffstats
path: root/lib/cpuset.c
diff options
context:
space:
mode:
authorHeiko Carstens2011-09-09 11:19:33 +0200
committerKarel Zak2011-09-10 00:00:33 +0200
commitf27ce0711cb9b2611a4bf679f83607439462cbb0 (patch)
tree8072a364c885e2c3c570397c427327f7430dc899 /lib/cpuset.c
parentlib,cpuset: fix stride handling in cpulist_parse() (diff)
downloadkernel-qcow2-util-linux-f27ce0711cb9b2611a4bf679f83607439462cbb0.tar.gz
kernel-qcow2-util-linux-f27ce0711cb9b2611a4bf679f83607439462cbb0.tar.xz
kernel-qcow2-util-linux-f27ce0711cb9b2611a4bf679f83607439462cbb0.zip
lib,cpuset: enforce stricter parsing of cpu lists
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@de.ibm.com>
Diffstat (limited to 'lib/cpuset.c')
-rw-r--r--lib/cpuset.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/cpuset.c b/lib/cpuset.c
index 85927553e..ebaffccfb 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;
}