* [PATCH] USB: chaoskey: Use kasprintf() over strcpy()/strcat()
@ 2018-02-17 4:55 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2018-02-17 4:55 UTC (permalink / raw)
To: Greg Kroah-Hartman, Keith Packard; +Cc: linux-kernel, linux-usb
Instead of kmalloc() with manually calculated values followed by
multiple strcpy()/strcat() calls, just fold it all into a single
kasprintf() call.
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
---
drivers/usb/misc/chaoskey.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
index 716cb515523e..cf5828ce927a 100644
--- a/drivers/usb/misc/chaoskey.c
+++ b/drivers/usb/misc/chaoskey.c
@@ -168,14 +168,10 @@ static int chaoskey_probe(struct usb_interface *interface,
*/
if (udev->product && udev->serial) {
- dev->name = kmalloc(strlen(udev->product) + 1 +
- strlen(udev->serial) + 1, GFP_KERNEL);
+ dev->name = kasprintf(GFP_KERNEL, "%s-%s", udev->product,
+ udev->serial);
if (dev->name == NULL)
goto out;
-
- strcpy(dev->name, udev->product);
- strcat(dev->name, "-");
- strcat(dev->name, udev->serial);
}
dev->interface = interface;
--
2.7.4
--
Kees Cook
Pixel Security
^ permalink raw reply related [flat|nested] 4+ messages in thread
* USB: chaoskey: Use kasprintf() over strcpy()/strcat()
@ 2018-02-17 4:55 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2018-02-17 4:55 UTC (permalink / raw)
To: Greg Kroah-Hartman, Keith Packard; +Cc: linux-kernel, linux-usb
Instead of kmalloc() with manually calculated values followed by
multiple strcpy()/strcat() calls, just fold it all into a single
kasprintf() call.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/usb/misc/chaoskey.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
index 716cb515523e..cf5828ce927a 100644
--- a/drivers/usb/misc/chaoskey.c
+++ b/drivers/usb/misc/chaoskey.c
@@ -168,14 +168,10 @@ static int chaoskey_probe(struct usb_interface *interface,
*/
if (udev->product && udev->serial) {
- dev->name = kmalloc(strlen(udev->product) + 1 +
- strlen(udev->serial) + 1, GFP_KERNEL);
+ dev->name = kasprintf(GFP_KERNEL, "%s-%s", udev->product,
+ udev->serial);
if (dev->name == NULL)
goto out;
-
- strcpy(dev->name, udev->product);
- strcat(dev->name, "-");
- strcat(dev->name, udev->serial);
}
dev->interface = interface;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] USB: chaoskey: Use kasprintf() over strcpy()/strcat()
@ 2018-02-17 6:28 ` Keith Packard
0 siblings, 0 replies; 4+ messages in thread
From: Keith Packard @ 2018-02-17 6:28 UTC (permalink / raw)
To: Kees Cook, Greg Kroah-Hartman; +Cc: linux-kernel, linux-usb
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Kees Cook <keescook@chromium.org> writes:
> Instead of kmalloc() with manually calculated values followed by
> multiple strcpy()/strcat() calls, just fold it all into a single
> kasprintf() call.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
--
-keith
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* USB: chaoskey: Use kasprintf() over strcpy()/strcat()
@ 2018-02-17 6:28 ` Keith Packard
0 siblings, 0 replies; 4+ messages in thread
From: Keith Packard @ 2018-02-17 6:28 UTC (permalink / raw)
To: Kees Cook, Greg Kroah-Hartman; +Cc: linux-kernel, linux-usb
Kees Cook <keescook@chromium.org> writes:
> Instead of kmalloc() with manually calculated values followed by
> multiple strcpy()/strcat() calls, just fold it all into a single
> kasprintf() call.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-02-17 6:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-17 4:55 [PATCH] USB: chaoskey: Use kasprintf() over strcpy()/strcat() Kees Cook
2018-02-17 4:55 ` Kees Cook
2018-02-17 6:28 ` [PATCH] " Keith Packard
2018-02-17 6:28 ` Keith Packard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.