Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/power turbostat: Use strtoul() for iteration parsing

Replace strtod() with strtoul() and check errno for -n/-N options, since
num_iterations and header_iterations are unsigned long counters. Reject
zero and conversion errors; negative inputs wrap to large positive values
per standard unsigned semantics.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

authored by

Kaushlendra Kumar and committed by
Len Brown
8e5c0cc3 a2b4d0f8

+8 -6
+8 -6
tools/power/x86/turbostat/turbostat.c
··· 11536 11536 /* Parsed earlier */ 11537 11537 break; 11538 11538 case 'n': 11539 - num_iterations = strtod(optarg, NULL); 11539 + num_iterations = strtoul(optarg, NULL, 0); 11540 + errno = 0; 11540 11541 11541 - if (num_iterations <= 0) { 11542 - fprintf(outf, "iterations %d should be positive number\n", num_iterations); 11542 + if (errno || num_iterations == 0) { 11543 + fprintf(outf, "invalid iteration count: %s\n", optarg); 11543 11544 exit(2); 11544 11545 } 11545 11546 break; 11546 11547 case 'N': 11547 - header_iterations = strtod(optarg, NULL); 11548 + header_iterations = strtoul(optarg, NULL, 0); 11549 + errno = 0; 11548 11550 11549 - if (header_iterations <= 0) { 11550 - fprintf(outf, "iterations %d should be positive number\n", header_iterations); 11551 + if (errno || header_iterations == 0) { 11552 + fprintf(outf, "invalid header iteration count: %s\n", optarg); 11551 11553 exit(2); 11552 11554 } 11553 11555 break;