summaryrefslogtreecommitdiff
path: root/drivers/staging/vme_user
diff options
context:
space:
mode:
authorCalvince Otieno <calvncce@gmail.com>2023-10-19 09:55:20 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-10-21 11:59:33 +0200
commitcf4381ee0bdb3c6a15d4b3e62fc4055050939772 (patch)
tree2d2137b2db12cd836349ce11c5a2da07f4bc54dd /drivers/staging/vme_user
parent017b9ef371e06f852e52b290e4e3c5b5fdf9ceba (diff)
staging: vme_user: replace strcpy with strscpy
Checkpatch suggests using strscpy() instead of strcpy(). The advantages of strscpy() are that it always adds a NUL terminator and prevents read/write overflows if the source string is not properly terminated. strcpy() lacks built-in bounds checking for the destination buffer, making it susceptible to buffer overflows. These overflows can lead to various unpredictable behaviors. In this specific context, both strscpy and strcpy performs the same operation without any functional difference. The reason for this equivalence is that the driver_name string "vme_fake" is shorter than the size of the fake_bridge->name array which is defined as 16 characters (struct vme_bridge {char name[VMENAMSIZ];...}). Thus, there is no risk of buffer overflow in either case. VMENAMSIZ variable holds a constant value of 16 (#define VMENAMSIZ 16) The null-terminated "vme_fake" string (static const char driver_name[] = "vme_fake";) can be safely copied into fake_bridge->name using either strscpy or strcpy. While using strscpy() does not address any bugs, it is considered a better practice and aligns with checkpatch recommendations. Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Calvince Otieno <calvncce@gmail.com> Link: https://lore.kernel.org/r/ZTDS2H48JBUTiwZi@lab-ubuntu Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/vme_user')
-rw-r--r--drivers/staging/vme_user/vme_fake.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/staging/vme_user/vme_fake.c b/drivers/staging/vme_user/vme_fake.c
index ae802d6dda7e..7f84d1c86f29 100644
--- a/drivers/staging/vme_user/vme_fake.c
+++ b/drivers/staging/vme_user/vme_fake.c
@@ -1091,7 +1091,7 @@ static int __init fake_init(void)
tasklet_init(&fake_device->int_tasklet, fake_VIRQ_tasklet,
(unsigned long)fake_bridge);
- strcpy(fake_bridge->name, driver_name);
+ strscpy(fake_bridge->name, driver_name, sizeof(fake_bridge->name));
/* Add master windows to list */
INIT_LIST_HEAD(&fake_bridge->master_resources);