Skip to content

Commit 99481d2

Browse files
Likhitha Korrapatishuahkh
authored andcommitted
cpupower: Fix cpuidle_set to accept only numeric values for idle-set operation.
For both the d and e options in 'cpupower idle_set' command, an atoi() conversion is done without checking if the input argument is all numeric. So, an atoi conversion is done on any character provided as input and the CPU idle_set operation continues with that integer value, which may not be what is intended or entirely correct. The output of cpuidle-set before patch is as follows: [root@xxx cpupower]# cpupower idle-set -e 1$ Idlestate 1 enabled on CPU 0 [snip] Idlestate 1 enabled on CPU 47 [root@xxx cpupower]# cpupower idle-set -e 11 Idlestate 11 not available on CPU 0 [snip] Idlestate 11 not available on CPU 47 [root@xxx cpupower]# cpupower idle-set -d 12 Idlestate 12 not available on CPU 0 [snip] Idlestate 12 not available on CPU 47 [root@xxx cpupower]# cpupower idle-set -d qw Idlestate 0 disabled on CPU 0 [snip] Idlestate 0 disabled on CPU 47 This patch adds a check for both d and e options in cpuidle-set.c to see that the idle_set value is all numeric before doing a string-to-int conversion using strtol(). The output of cpuidle-set after the patch is as below: [root@xxx cpupower]# ./cpupower idle-set -e 1$ Bad idle_set value: 1$. Integer expected [root@xxx cpupower]# ./cpupower idle-set -e 11 Idlestate 11 not available on CPU 0 [snip] Idlestate 11 not available on CPU 47 [root@xxx cpupower]# ./cpupower idle-set -d 12 Idlestate 12 not available on CPU 0 [snip] Idlestate 12 not available on CPU 47 [root@xxx cpupower]# ./cpupower idle-set -d qw Bad idle_set value: qw. Integer expected Signed-off-by: Brahadambal Srinivasan <latha@linux.vnet.ibm.com> Signed-off-by: Likhitha Korrapati <likhitha@linux.ibm.com> Tested-by: Pavithra Prakash <pavrampu@linux.vnet.ibm.com> Reviewed-by: Rick Lindsley <ricklind@linux.vnet.ibm.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent eb426fc commit 99481d2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tools/power/cpupower/utils/cpuidle-set.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,20 @@ int cmd_idle_set(int argc, char **argv)
4141
cont = 0;
4242
break;
4343
case 'd':
44-
if (param) {
45-
param = -1;
46-
cont = 0;
47-
break;
48-
}
49-
param = ret;
50-
idlestate = atoi(optarg);
51-
break;
5244
case 'e':
5345
if (param) {
5446
param = -1;
5547
cont = 0;
5648
break;
5749
}
5850
param = ret;
59-
idlestate = atoi(optarg);
51+
strtol(optarg, &endptr, 10);
52+
if (*endptr != '\0') {
53+
printf(_("Bad value: %s, Integer expected\n"), optarg);
54+
exit(EXIT_FAILURE);
55+
} else {
56+
idlestate = atoi(optarg);
57+
}
6058
break;
6159
case 'D':
6260
if (param) {

0 commit comments

Comments
 (0)