platform/surface: Replace deprecated strcpy in surface_button_add
Subsystems (3)
PATCH 1/1 platform/surface: Replace deprecated strcpy in surface_button_add
strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the safer strscpy(). No functional changes.
--- drivers/platform/surface/surfacepro3_button.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/surface/surfacepro3_button.c +2 -1
@@ -10,6 +10,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> +#include <linux/string.h> #include <linux/types.h> #include <linux/input.h> #include <linux/acpi.h>
@@ -211,7 +212,7 @@ static int surface_button_add(struct acpi_device *device) } name =acpi_device_name (device); -strcpy (name,SURFACE_BUTTON_DEVICE_NAME ); +strscpy (acpi_device_name (device),SURFACE_BUTTON_DEVICE_NAME );snprintf (button->phys,sizeof (button->phys),"%s/buttons" , hid); input->name = name;
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Chen, Yu C
maintainerHi Thorsten,
Quoted 23 lines · Thorsten Blum
strcpy()has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the saferstrscpy(). No functional changes.Signed-off-by Thorsten Blum <[email protected]>--- drivers/platform/surface/surfacepro3_button.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/platform/surface/surfacepro3_button.c +1
-0@@ -10,6 +10,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> +#include <linux/string.h> #include <linux/types.h> #include <linux/input.h> #include <linux/acpi.h>
drivers/platform/surface/surfacepro3_button.c static int surface_button_add(struct acpi_device *device) · line 215
Quoted 5 lines
drivers/platform/surface/surfacepro3_button.c +1
-1@@ -211,7 +212,7 @@ static int surface_button_add(struct acpi_device *device) } name =acpi_device_name (device); -strcpy (name,SURFACE_BUTTON_DEVICE_NAME ); +strscpy (acpi_device_name (device),SURFACE_BUTTON_DEVICE_NAME );
Thanks for the fix, a minor question might be why we do not reuse name by strscpy(name, SURFACE_BUTTON_DEVICE_NAME) ?
thanks,
Chenyu
Quoted 3 lines
drivers/platform/surface/surfacepro3_button.c +0
-0snprintf (button->phys,sizeof (button->phys),"%s/buttons" , hid); input->name = name;
Quoted 5 lines · Yu C
drivers/platform/surface/surfacepro3_button.c static int surface_button_add(struct acpi_device *device) · line 215
Quoted 2 lines
drivers/platform/surface/surfacepro3_button.c +1
-1-strcpy (name,SURFACE_BUTTON_DEVICE_NAME ); +strscpy (acpi_device_name (device),SURFACE_BUTTON_DEVICE_NAME );Thanks for the fix, a minor question might be why we do not reuse name by
strscpy(name, SURFACE_BUTTON_DEVICE_NAME)?
Because 'name' is a 'char *' from which the size of the destination buffer cannot be inferred by the 2-argument version of strscpy().
Using 'name' would force us to use strscpy() with 3 arguments:
strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
Thanks,
Thorsten
Ilpo Järvinen
maintainerQuoted 7 lines · Thorsten Blum
Quoted 5 lines · Yu C
drivers/platform/surface/surfacepro3_button.c static int surface_button_add(struct acpi_device *device) · line 215
Quoted 2 lines
drivers/platform/surface/surfacepro3_button.c +1
-1-strcpy (name,SURFACE_BUTTON_DEVICE_NAME ); +strscpy (acpi_device_name (device),SURFACE_BUTTON_DEVICE_NAME );Thanks for the fix, a minor question might be why we do not reuse name by
strscpy(name, SURFACE_BUTTON_DEVICE_NAME)?
Quoted 6 lines
Because 'name' is a 'char *' from which the size of the destination buffer cannot be inferred by the 2-argument version of
strscpy().Using 'name' would force us to use
strscpy()with 3 arguments:
strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
I suggest you just remove 'name' instead. It seems pretty useless to begin with but especially after your patch. :-)
Please also add () to the subject line after function names.
Signature · 1 line
i.
Chen, Yu C
maintainerQuoted 12 lines · Ilpo Järvinen
Quoted 10 lines · Thorsten Blum
Quoted 5 lines · Yu C
drivers/platform/surface/surfacepro3_button.c static int surface_button_add(struct acpi_device *device) · line 215
Quoted 2 lines
drivers/platform/surface/surfacepro3_button.c +1
-1-strcpy (name,SURFACE_BUTTON_DEVICE_NAME ); +strscpy (acpi_device_name (device),SURFACE_BUTTON_DEVICE_NAME );Thanks for the fix, a minor question might be why we do not reuse name by
strscpy(name, SURFACE_BUTTON_DEVICE_NAME)?Because 'name' is a 'char *' from which the size of the destination buffer cannot be inferred by the 2-argument version of
strscpy().
Quoted 6 lines
Quoted 3 lines
Using 'name' would force us to use
strscpy()with 3 arguments:
strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);I suggest you just remove 'name' instead. It seems pretty useless to begin with but especially after your patch. :-)
It was still used by other places.
thanks,
Chenyu
Quoted 3 lines
Please also add () to the subject line after function names.
Quoted 7 lines · Thorsten Blum
Quoted 5 lines · Yu C
drivers/platform/surface/surfacepro3_button.c static int surface_button_add(struct acpi_device *device) · line 215
Quoted 2 lines
drivers/platform/surface/surfacepro3_button.c +1
-1-strcpy (name,SURFACE_BUTTON_DEVICE_NAME ); +strscpy (acpi_device_name (device),SURFACE_BUTTON_DEVICE_NAME );Thanks for the fix, a minor question might be why we do not reuse name by
strscpy(name, SURFACE_BUTTON_DEVICE_NAME)?
Quoted 7 lines
Because 'name' is a 'char *' from which the size of the destination buffer cannot be inferred by the 2-argument version of
strscpy().Using 'name' would force us to use
strscpy()with 3 arguments:
strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
Thanks for the explanation!
thanks,
Chenyu
Quoted 3 lines
Thanks,
Thorsten