]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools/power turbostat: Use strtoul() for iteration parsing
authorKaushlendra Kumar <kaushlendra.kumar@intel.com>
Mon, 8 Dec 2025 03:08:04 +0000 (08:38 +0530)
committerLen Brown <len.brown@intel.com>
Fri, 13 Feb 2026 20:03:17 +0000 (14:03 -0600)
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>
tools/power/x86/turbostat/turbostat.c

index 5239fd971b66a638f854e59432ec391b2699364f..b8cbbff95e845ef839b249339736b3e7d62b0c7e 100644 (file)
@@ -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;