From 58b3ef0e6fe2a78c4b89cbc1024f3ed3915593da Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 26 Jan 2015 19:16:52 +0300 Subject: [PATCH] Fix --cpu-cap option parsing, v2 Manage to forgot to increase pointer by length of the words parsed. Reported-by: Mark O'Neill Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- crtools.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/crtools.c b/crtools.c index 552626575..cf2fdf24c 100644 --- a/crtools.c +++ b/crtools.c @@ -105,26 +105,36 @@ static int parse_cpu_cap(struct cr_options *opts, const char *optarg) return 0; } - for (; *optarg; optarg++) { + while (*optarg) { if (optarg[0] == '^') { inverse = !inverse; + optarg++; continue; } else if (optarg[0] == ',') { inverse = false; + optarg++; continue; } - if (!strncmp(optarg, "fpu", 3)) + if (!strncmp(optarg, "fpu", 3)) { ____cpu_set_cap(opts, CPU_CAP_FPU, inverse); - else if (!strncmp(optarg, "all", 3)) + optarg += 3; + } else if (!strncmp(optarg, "all", 3)) { ____cpu_set_cap(opts, CPU_CAP_ALL, inverse); - else if (!strncmp(optarg, "none", 3)) - ____cpu_set_cap(opts, CPU_CAP_NONE, inverse); - else if (!strncmp(optarg, "cpu", 3)) + optarg += 3; + } else if (!strncmp(optarg, "none", 4)) { + if (inverse) + opts->cpu_cap = CPU_CAP_ALL; + else + opts->cpu_cap = CPU_CAP_NONE; + optarg += 4; + } else if (!strncmp(optarg, "cpu", 3)) { ____cpu_set_cap(opts, CPU_CAP_CPU, inverse); - else if (!strncmp(optarg, "ins", 3)) + optarg += 3; + } else if (!strncmp(optarg, "ins", 3)) { ____cpu_set_cap(opts, CPU_CAP_INS, inverse); - else + optarg += 3; + } else goto Esyntax; } #undef ____cpu_set_cap