Skip to content

Commit abe6db6

Browse files
JustinStittkees
authored andcommitted
HID: prodikeys: Replace deprecated strncpy() with strscpy()
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: KSPP#90 Cc: [email protected] Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/20230914-strncpy-drivers-hid-hid-prodikeys-c-v1-1-10c00550f2c2@google.com Signed-off-by: Kees Cook <[email protected]>
1 parent 9b9056a commit abe6db6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/hid/hid-prodikeys.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,9 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm)
639639
goto fail;
640640
}
641641

642-
strncpy(card->driver, shortname, sizeof(card->driver));
643-
strncpy(card->shortname, shortname, sizeof(card->shortname));
644-
strncpy(card->longname, longname, sizeof(card->longname));
642+
strscpy(card->driver, shortname, sizeof(card->driver));
643+
strscpy(card->shortname, shortname, sizeof(card->shortname));
644+
strscpy(card->longname, longname, sizeof(card->longname));
645645

646646
/* Set up rawmidi */
647647
err = snd_rawmidi_new(card, card->shortname, 0,
@@ -652,7 +652,7 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm)
652652
goto fail;
653653
}
654654
pm->rwmidi = rwmidi;
655-
strncpy(rwmidi->name, card->shortname, sizeof(rwmidi->name));
655+
strscpy(rwmidi->name, card->shortname, sizeof(rwmidi->name));
656656
rwmidi->info_flags = SNDRV_RAWMIDI_INFO_INPUT;
657657
rwmidi->private_data = pm;
658658

0 commit comments

Comments
 (0)