[CRIU] [PATCH] Fix --cpu-cap option parsing

Cyrill Gorcunov gorcunov at openvz.org
Mon Jan 26 08:17:22 PST 2015


Manage to forgot to increase pointer by length
of the words parsed.

Reported-by: Mark O'Neill <mao at tumblingdice.co.uk>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 crtools.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/crtools.c b/crtools.c
index 1f1f5501cb6a..85e8ce97393c 100644
--- a/crtools.c
+++ b/crtools.c
@@ -105,7 +105,7 @@ static int parse_cpu_cap(struct cr_options *opts, const char *optarg)
 		return 0;
 	}
 
-	for (; *optarg; optarg++) {
+	while (*optarg) {
 		if (optarg[0] == '^') {
 			inverse = !inverse;
 			continue;
@@ -114,17 +114,25 @@ static int parse_cpu_cap(struct cr_options *opts, const char *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
-- 
1.9.3



More information about the CRIU mailing list