3a677fb
From cb8e390d258b7f8073afafcbb163976e27346e9d Mon Sep 17 00:00:00 2001
3a677fb
From: Josh Boyer <jwboyer@fedoraproject.org>
3a677fb
Date: Fri, 11 Oct 2013 08:37:53 -0400
3a677fb
Subject: [PATCH] cpupower: Fix segfault due to incorrect getopt_long arugments
3a677fb
3a677fb
If a user calls 'cpupower set --perf-bias 15', the process will end with a
3a677fb
SIGSEGV in libc because cpupower-set passes a NULL optarg to the atoi call.
3a677fb
This is because the getopt_long structure currently has all of the options
3a677fb
as having an optional_argument when they really have a required argument.
3a677fb
We change the structure to use required_argument to match the short options
3a677fb
and it resolves the issue.
3a677fb
3a677fb
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1000439
3a677fb
3a677fb
Cc: stable@vger.kernel.org
3a677fb
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
3a677fb
---
3a677fb
 tools/power/cpupower/utils/cpupower-set.c | 6 +++---
3a677fb
 1 file changed, 3 insertions(+), 3 deletions(-)
3a677fb
3a677fb
diff --git a/tools/power/cpupower/utils/cpupower-set.c b/tools/power/cpupower/utils/cpupower-set.c
3a677fb
index dc4de37..bcf1d2f 100644
3a677fb
--- a/tools/power/cpupower/utils/cpupower-set.c
3a677fb
+++ b/tools/power/cpupower/utils/cpupower-set.c
3a677fb
@@ -18,9 +18,9 @@
3a677fb
 #include "helpers/bitmask.h"
3a677fb
 
3a677fb
 static struct option set_opts[] = {
3a677fb
-	{ .name = "perf-bias",	.has_arg = optional_argument,	.flag = NULL,	.val = 'b'},
3a677fb
-	{ .name = "sched-mc",	.has_arg = optional_argument,	.flag = NULL,	.val = 'm'},
3a677fb
-	{ .name = "sched-smt",	.has_arg = optional_argument,	.flag = NULL,	.val = 's'},
3a677fb
+	{ .name = "perf-bias",	.has_arg = required_argument,	.flag = NULL,	.val = 'b'},
3a677fb
+	{ .name = "sched-mc",	.has_arg = required_argument,	.flag = NULL,	.val = 'm'},
3a677fb
+	{ .name = "sched-smt",	.has_arg = required_argument,	.flag = NULL,	.val = 's'},
3a677fb
 	{ },
3a677fb
 };
3a677fb
 
3a677fb
-- 
3a677fb
1.8.3.1
3a677fb