]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: gadget: f_midi: prefer strscpy() over strcpy()
authorAbdul Rahim <abdul.rahim@myyahoo.com>
Sat, 14 Sep 2024 23:17:49 +0000 (04:47 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 13:12:30 +0000 (15:12 +0200)
The function strcpy() is depreciated and potentially unsafe. It performs
no bounds checking on the destination buffer. This could result in
linear overflows beyond the end of the buffer, leading to all kinds of
misbehaviors. The safe replacement is strscpy() [1].

this fixes checkpatch warning:
    WARNING: Prefer strscpy over strcpy

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Signed-off-by: Abdul Rahim <abdul.rahim@myyahoo.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/20240914231756.503521-1-abdul.rahim@myyahoo.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_midi.c

index 1067847cc07995150368f57fab2469fc81e5ab5f..837fcdfa3840ff1dc2fbe819c858f8ab91d915c6 100644 (file)
@@ -819,9 +819,9 @@ static int f_midi_register_card(struct f_midi *midi)
                goto fail;
        }
 
-       strcpy(card->driver, f_midi_longname);
-       strcpy(card->longname, f_midi_longname);
-       strcpy(card->shortname, f_midi_shortname);
+       strscpy(card->driver, f_midi_longname);
+       strscpy(card->longname, f_midi_longname);
+       strscpy(card->shortname, f_midi_shortname);
 
        /* Set up rawmidi */
        snd_component_add(card, "MIDI");
@@ -833,7 +833,7 @@ static int f_midi_register_card(struct f_midi *midi)
        }
        midi->rmidi = rmidi;
        midi->in_last_port = 0;
-       strcpy(rmidi->name, card->shortname);
+       strscpy(rmidi->name, card->shortname);
        rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
                            SNDRV_RAWMIDI_INFO_INPUT |
                            SNDRV_RAWMIDI_INFO_DUPLEX;