ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
Subsystems (2)
PATCH v2 1/1 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 expected 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.
---
v2: Replace atoi() with strtol() to filter the number. (Rafael)
--- tools/power/acpi/tools/pfrut/pfrut.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
tools/power/acpi/tools/pfrut/pfrut.c +15 -3
@@ -97,7 +97,7 @@ static struct option long_options[] = {static void parse_options (int argc,char **argv) {int option_index =0 ; -char *pathname; +char *pathname, *endptr;int opt; pathname =strdup (argv[0 ]);
@@ -125,11 +125,23 @@ static void parse_options(int argc, char **argv) log_getinfo =1 ;break ;case 'T' : - log_type =atoi (optarg); + log_type =strtol (optarg, &endptr,0 ); +if (*endptr || (log_type !=0 && log_type !=1 )) { +printf ("Number expected: type(0:execution, 1:history) - Quit.\n" ); +exit (1 ); + } + set_log_type =1 ;break ;case 'L' : - log_level =atoi (optarg); + log_level =strtol (optarg, &endptr,0 ); +if (*endptr || + (log_level !=0 && log_level !=1 && + log_level !=2 && log_level !=4 )) { +printf ("Number expected: level(0, 1, 2, 4) - Quit.\n" ); +exit (1 ); + } + set_log_level =1 ;break ;case 'R' :
Signature · 1 line
2.25.1
Quoted 74 lines · Chen Yu
The user provides arbitrary non-numeic value to level and type, which could bring expected behavior. In this case the expected behavior would be to throw an error.
pfrut -h
usage: pfrut [OPTIONS]
code injection:(quoted diff) +0
-6-l, --load -s, --stage -a, --activate -u, --update [stage and activate] -q, --query -d, --revidupdate telemetry:
(quoted diff) +0
-5-G, --getloginfo -T, --type(0:execution, 1:history) -L, --level(0, 1, 2, 4) -R, --read -D, --revid log pfrut -T A pfrut -Glog_level:0
log_type:0
log_revid:2
max_data_size:65536
chunk1_size:0
chunk2_size:1530
rollover_cnt:0
reset_cnt:17Fix 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]>---
v2: Replaceatoi()withstrtol()to filter the number. (Rafael)--- tools/power/acpi/tools/pfrut/pfrut.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)tools/power/acpi/tools/pfrut/pfrut.c +9
-3@@ -97,7 +97,7 @@ static struct option long_options[] = {static void parse_options (int argc,char **argv) {int option_index =0 ; -char *pathname; +char *pathname, *endptr;int opt; pathname =strdup (argv[0 ]);@@ -125,11 +125,23 @@ static void parse_options(int argc, char **argv) log_getinfo =1 ;break ;case 'T' : - log_type =atoi (optarg); + log_type =strtol (optarg, &endptr,0 ); +if (*endptr || (log_type !=0 && log_type !=1 )) { +printf ("Number expected: type(0:execution, 1:history) - Quit.\n" ); +exit (1 ); + } + set_log_type =1 ;break ;case 'L' : - log_level =atoi (optarg); + log_level =strtol (optarg, &endptr,0 ); + if (*endptr ||
tools/power/acpi/tools/pfrut/pfrut.c static void parse_options(int argc, char **argv)
Quoted 10 lines
tools/power/acpi/tools/pfrut/pfrut.c +6
-1+ (log_level != 0 && log_level != 1 && + log_level != 2 && log_level != 4)) { +printf ("Number expected: level(0, 1, 2, 4) - Quit.\n" ); +exit (1 ); + } + set_log_level =1 ;break ;case 'R' : --
Applied as 6.3-rc material, thanks!