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 for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250323143111.79886-1-kendra.j.moore3443@gmail.com>
Date: Sun, 23 Mar 2025 10:31:11 -0400
From: kendrajmoore <kendra.j.moore3443@...il.com>
To: linux-pm@...r.kernel.org
Cc: lenb@...nel.org,
	linux-kernel@...r.kernel.org,
	Kendra Moore <kendra.j.moore3443@...il.com>
Subject: [PATCH] Replace strncpy with strscpy to ensure null-termination

From: Kendra Moore <kendra.j.moore3443@...il.com>

The field pcounter->name is used as a null-terminated string.
Using strncpy() with ARRAY_SIZE - 1 does not guarantee
null-termination and can lead to undefined behavior if the source
is too long.

This patch replaces it with strscpy() which ensures
null-termination and returns an error code if truncation occurs.

Signed-off-by: Kendra Moore <kendra.j.moore3443@...il.com>
---
 tools/power/x86/turbostat/turbostat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 8d5011a0bf60..8f24e18d3de0 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -9345,7 +9345,7 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum
 	}
 
 	if (new_counter) {
-		strncpy(pcounter->name, name, ARRAY_SIZE(pcounter->name) - 1);
+		strscpy(pcounter->name, name, ARRAY_SIZE(pcounter->name));
 		pcounter->type = type;
 		pcounter->scope = scope;
 		pcounter->lsb = lsb;
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ