Skip to content

Commit

Permalink
tools/power x86_energy_perf_policy: Fix argument parsing
Browse files Browse the repository at this point in the history
The -w argument in x86_energy_perf_policy currently triggers an
unconditional segfault.

This is because the argument string reads: "+a:c:dD:E:e:f:m:M:rt:u:vw" and
yet the argument handler expects an argument.

When parse_optarg_string is called with a null argument, we then proceed to
crash in strncmp, not horribly friendly.

The man page describes -w as taking an argument, the long form
(--hwp-window) is correctly marked as taking a required argument, and the
code expects it.

As such, this patch simply marks the short form (-w) as requiring an
argument.

Signed-off-by: Zephaniah E. Loss-Cutler-Hull <[email protected]>
Signed-off-by: Len Brown <[email protected]>
  • Loading branch information
Zephaniah E. Loss-Cutler-Hull authored and lenb committed Aug 31, 2019
1 parent f3fe116 commit 0353148
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ void cmdline(int argc, char **argv)

progname = argv[0];

while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw",
while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw:",
long_options, &option_index)) != -1) {
switch (opt) {
case 'a':
Expand Down

0 comments on commit 0353148

Please sign in to comment.