]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
USB: gadget: Replace deprecated strncpy() with strscpy()
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 20 Mar 2025 16:56:44 +0000 (17:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Apr 2025 14:08:33 +0000 (16:08 +0200)
strncpy() is deprecated for NUL-terminated destination buffers; use
strscpy() instead. Since kzalloc() already zeroes out the destination
buffer, the potential NUL-padding by strncpy() is unnecessary. strscpy()
copies only the required characters and guarantees NUL-termination.

Since the destination buffer has a fixed length, strscpy() automatically
determines its size using sizeof() when the argument is omitted. This
makes an explicit sizeof() call unnecessary.

The source string is also NUL-terminated and meets the __must_be_cstr()
requirement of strscpy().

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/20250320165647.34859-2-thorsten.blum@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/legacy/inode.c

index b6a30d88a800347de9d8e274923bd24b58018b53..fcce84a726f2cfeb47acfc7620203b29b1e28815 100644 (file)
@@ -1615,7 +1615,7 @@ static int activate_ep_files (struct dev_data *dev)
                mutex_init(&data->lock);
                init_waitqueue_head (&data->wait);
 
-               strncpy (data->name, ep->name, sizeof (data->name) - 1);
+               strscpy(data->name, ep->name);
                refcount_set (&data->count, 1);
                data->dev = dev;
                get_dev (dev);