lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220413192901.179470-1-h0tc0d3@gmail.com>
Date:   Wed, 13 Apr 2022 22:29:00 +0300
From:   Grigory Vasilyev <h0tc0d3@...il.com>
To:     unlisted-recipients:; (no To-header on input)
Cc:     Grigory Vasilyev <h0tc0d3@...il.com>, linux-kernel@...r.kernel.org
Subject: [PATCH] tools/x86_energy_perf_policy: Fix comparing int with LONG_MIN and LONG_MAX

A condition that will never be met.
strtol return long value but we have int variable and strtool can
overflow it.

Remove meaningless extra overflow comparisons.

Warning:

x86_energy_perf_policy.c:337:25:
warning: result of comparison of constant 9223372036854775807
with expression of type 'int' is always false
        if (i == LONG_MIN || i == LONG_MAX)
                             ~ ^  ~~~~~~~~
x86_energy_perf_policy.c:337:8:
warning: result of comparison of constant -9223372036854775808
with expression of type 'int' is always false
        if (i == LONG_MIN || i == LONG_MAX)

Signed-off-by: Grigory Vasilyev <h0tc0d3@...il.com>
---
 .../x86_energy_perf_policy/x86_energy_perf_policy.c  | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
index 5fd9e594079c..5fd7e2d4cd0e 100644
--- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
+++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
@@ -308,7 +308,7 @@ int parse_cmdline_turbo(int i)
 
 int parse_optarg_string(char *s)
 {
-	int i;
+	long i;
 	char *endptr;
 
 	if (!strncmp(s, "default", 7))
@@ -334,15 +334,11 @@ int parse_optarg_string(char *s)
 		fprintf(stderr, "no digits in \"%s\"\n", s);
 		usage();
 	}
-	if (i == LONG_MIN || i == LONG_MAX)
-		errx(-1, "%s", s);
 
-	if (i > 0xFF)
-		errx(-1, "%d (0x%x) must be < 256", i, i);
+	if (i < 0 || i > 255)
+		errx(-1, "%ld (0x%lx) must be >= 0 and < 256", i, i);
 
-	if (i < 0)
-		errx(-1, "%d (0x%x) must be >= 0", i, i);
-	return i;
+	return (int)i;
 }
 
 void parse_cmdline_all(char *s)
-- 
2.35.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ