Skip to content

Commit 66f8a4a

Browse files
JustinStittkees
authored andcommitted
hwmon: (ibmpowernv) Replace deprecated strncpy() with memcpy()
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. A suitable replacement is `memcpy` as we've already precisely calculated the number of bytes to copy while `buf` has been explicitly zero-initialized: | char buf[8] = { 0 }; Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: KSPP#90 Cc: [email protected] Signed-off-by: Justin Stitt <[email protected]> Tested-by: Michael Ellerman <[email protected]> Acked-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/20230919-strncpy-drivers-hwmon-ibmpowernv-c-v2-1-37d3e64172bc@google.com Signed-off-by: Kees Cook <[email protected]>
1 parent abe6db6 commit 66f8a4a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/hwmon/ibmpowernv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static int get_sensor_index_attr(const char *name, u32 *index, char *attr)
234234
if (copy_len >= sizeof(buf))
235235
return -EINVAL;
236236

237-
strncpy(buf, hash_pos + 1, copy_len);
237+
memcpy(buf, hash_pos + 1, copy_len);
238238

239239
err = kstrtou32(buf, 10, index);
240240
if (err)

0 commit comments

Comments
 (0)