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: <20250411135535.41423-1-kevinpaul468@gmail.com>
Date: Fri, 11 Apr 2025 19:25:35 +0530
From: Kevin Paul Reddy Janagari <kevinpaul468@...il.com>
To: shuah@...nel.org
Cc: linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	kevinpaul468@...il.com
Subject: [PATCH] selftests: Removing deprecated strncpy()

This patch suggests the replacement of strncpy with strscpy
as per Documentation/process/deprecated.
The strncpy() fails to guarantee NULL termination,
The function adds zero pads which isn't really convenient for short strings
as it may cause performance issues.

strscpy() is a preferred replacement because
it overcomes the limitations of strncpy mentioned above.

Compile Tested

Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@...il.com>
---
 tools/testing/selftests/sync/sync.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/sync/sync.c b/tools/testing/selftests/sync/sync.c
index 7741c0518d18..4b284f517433 100644
--- a/tools/testing/selftests/sync/sync.c
+++ b/tools/testing/selftests/sync/sync.c
@@ -29,8 +29,8 @@
 #include <malloc.h>
 #include <poll.h>
 #include <stdint.h>
-#include <string.h>
 #include <unistd.h>
+#include <linux/string.h>
 
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -71,7 +71,7 @@ int sync_merge(const char *name, int fd1, int fd2)
 	int err;
 
 	data.fd2 = fd2;
-	strncpy(data.name, name, sizeof(data.name) - 1);
+	strscpy(data.name, name, sizeof(data.name) - 1);
 	data.name[sizeof(data.name) - 1] = '\0';
 
 	err = ioctl(fd1, SYNC_IOC_MERGE, &data);
@@ -198,7 +198,7 @@ int sw_sync_fence_create(int fd, const char *name, unsigned int value)
 	int err;
 
 	data.value = value;
-	strncpy(data.name, name, sizeof(data.name) - 1);
+	strscpy(data.name, name, sizeof(data.name) - 1);
 	data.name[sizeof(data.name) - 1] = '\0';
 
 	err = ioctl(fd, SW_SYNC_IOC_CREATE_FENCE, &data);
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ