diff options
| author | Kaushlendra Kumar <kaushlendra.kumar@intel.com> | 2025-12-08 06:08:04 +0300 |
|---|---|---|
| committer | Len Brown <len.brown@intel.com> | 2026-02-13 23:03:17 +0300 |
| commit | 8e5c0cc326f2e95a71bb6e6063e65caa60c8f951 (patch) | |
| tree | 5b6dfabd7c0a333fd1454cf1f660dd66a58e0971 /tools | |
| parent | a2b4d0f8bf07a4a4fe8a526e10c45e593c7a3bf0 (diff) | |
| download | linux-8e5c0cc326f2e95a71bb6e6063e65caa60c8f951.tar.xz | |
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>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 5239fd971b66..b8cbbff95e84 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -11536,18 +11536,20 @@ void cmdline(int argc, char **argv) /* Parsed earlier */ break; case 'n': - num_iterations = strtod(optarg, NULL); + num_iterations = strtoul(optarg, NULL, 0); + errno = 0; - if (num_iterations <= 0) { - fprintf(outf, "iterations %d should be positive number\n", num_iterations); + if (errno || num_iterations == 0) { + fprintf(outf, "invalid iteration count: %s\n", optarg); exit(2); } break; case 'N': - header_iterations = strtod(optarg, NULL); + header_iterations = strtoul(optarg, NULL, 0); + errno = 0; - if (header_iterations <= 0) { - fprintf(outf, "iterations %d should be positive number\n", header_iterations); + if (errno || header_iterations == 0) { + fprintf(outf, "invalid header iteration count: %s\n", optarg); exit(2); } break; |
