Skip to contentSkip to conversation

staging: vme_user: Replace strcpy with strscpy

PATCH In review Jonathan Bergh 2 participants 3 messages Sep 17, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: vme_user: Replace strcpy with strscpy

Replace strcpy with strscpy as preferred by checkpatch in vme_fake.c to prevent warnings.

---
 drivers/staging/vme_user/vme_fake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vme_user/vme_fake.c +1 -1
index 9bcb89a84d53..0cf5700e151f 100644
@@ -1093,7 +1093,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);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 13 lines · Jonathan Bergh

Replace strcpy with strscpy as preferred by checkpatch in vme_fake.c to prevent warnings.

---
 drivers/staging/vme_user/vme_fake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vme_user/vme_fake.c +0 -0
index 9bcb89a84d53..0cf5700e151f 100644

drivers/staging/vme_user/vme_fake.c static int __init fake_init(void) · line 1096

Quoted 5 lines
drivers/staging/vme_user/vme_fake.c +1 -1
@@ -1093,7 +1093,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));

If it were this easy, we would have swept the tree and done so, right? Are you sure this is correct? If so, please document exactly why it is correct in the changelog text when you resend this.

thanks,

greg k-h

#2 lore raw
Quoted 17 lines · Greg KH
Quoted 16 lines · Jonathan Bergh

Replace strcpy with strscpy as preferred by checkpatch in vme_fake.c to prevent warnings.

---
 drivers/staging/vme_user/vme_fake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vme_user/vme_fake.c +0 -0
index 9bcb89a84d53..0cf5700e151f 100644
@@ -1093,7 +1093,7 @@ static int __init fake_init(void)
 	tasklet_init(&fake_device->int_tasklet, fake_VIRQ_tasklet,
 			(unsigned long) fake_bridge);
 
Quoted 3 lines

drivers/staging/vme_user/vme_fake.c static int __init fake_init(void) · line 1096

Quoted 2 lines
drivers/staging/vme_user/vme_fake.c +1 -1
-	strcpy(fake_bridge->name, driver_name);
+	strscpy(fake_bridge->name, driver_name, sizeof(fake_bridge->name));

Hi, thanks a lot for the review + comment.

Quoted 3 lines

If it were this easy, we would have swept the tree and done so, right? Are you sure this is correct? If so, please document exactly why it is correct in the changelog text when you resend this.

Thought it better to discuss before sending an updated patch that might be wrong.

I think it is correct since driver_name:
* In: vme_fake.c:

	static const char driver_name[] = "vme_fake": 

will always fit into vme_bridge->name:
* In: vme_bridge.h:

	...
	#define VMENAMSIZ 16
	...
	struct vme_bridge {
		...
		char name[VMENAMSIZ];
		...
	}

but I could have missed something. This is in the module __init method and i dont see that name pointer being reassigned before the strcpy call (which was changed).

Maybe its not worth changing, but (if it is correct) it would get rid of the checkpatch warning and convert to the "preferred" API?

Quoted 4 lines

thanks,

greg k-h

FWIW Wouldnt it always be better to use the "safe" option since it at worst its going to truncate the destination string rather than write off the end of the array?

thanks in advance
cheers
Jonathan