Skip to content

Commit 0bc23d8

Browse files
yu-chen-surfrafaeljw
authored andcommitted
ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
The user provides arbitrary non-numeic value to level and type, which could bring unexpected behavior. In this case the expected behavior would be to throw an error. pfrut -h usage: pfrut [OPTIONS] code injection: -l, --load -s, --stage -a, --activate -u, --update [stage and activate] -q, --query -d, --revid update telemetry: -G, --getloginfo -T, --type(0:execution, 1:history) -L, --level(0, 1, 2, 4) -R, --read -D, --revid log pfrut -T A pfrut -G log_level:0 log_type:0 log_revid:2 max_data_size:65536 chunk1_size:0 chunk2_size:1530 rollover_cnt:0 reset_cnt:17 Fix this by restricting the input to be in the expected range. Reported-by: Hariganesh Govindarajulu <[email protected]> Suggested-by: "Rafael J. Wysocki" <[email protected]> Signed-off-by: Chen Yu <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent eeac8ed commit 0bc23d8

File tree

1 file changed

+15
-3
lines changed
  • tools/power/acpi/tools/pfrut

1 file changed

+15
-3
lines changed

tools/power/acpi/tools/pfrut/pfrut.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static struct option long_options[] = {
9797
static void parse_options(int argc, char **argv)
9898
{
9999
int option_index = 0;
100-
char *pathname;
100+
char *pathname, *endptr;
101101
int opt;
102102

103103
pathname = strdup(argv[0]);
@@ -125,11 +125,23 @@ static void parse_options(int argc, char **argv)
125125
log_getinfo = 1;
126126
break;
127127
case 'T':
128-
log_type = atoi(optarg);
128+
log_type = strtol(optarg, &endptr, 0);
129+
if (*endptr || (log_type != 0 && log_type != 1)) {
130+
printf("Number expected: type(0:execution, 1:history) - Quit.\n");
131+
exit(1);
132+
}
133+
129134
set_log_type = 1;
130135
break;
131136
case 'L':
132-
log_level = atoi(optarg);
137+
log_level = strtol(optarg, &endptr, 0);
138+
if (*endptr ||
139+
(log_level != 0 && log_level != 1 &&
140+
log_level != 2 && log_level != 4)) {
141+
printf("Number expected: level(0, 1, 2, 4) - Quit.\n");
142+
exit(1);
143+
}
144+
133145
set_log_level = 1;
134146
break;
135147
case 'R':

0 commit comments

Comments
 (0)