linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* USB: chaoskey: Use kasprintf() over strcpy()/strcat()
@ 2018-02-17  6:28 Keith Packard
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread
* USB: chaoskey: Use kasprintf() over strcpy()/strcat()
@ 2018-02-17  4:55 Kees Cook
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2018-02-17  6:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-17  6:28 USB: chaoskey: Use kasprintf() over strcpy()/strcat() Keith Packard
  -- strict thread matches above, loose matches on Subject: below --
2018-02-17  4:55 Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).