Skip to content

Commit 5f6af00

Browse files
committed
ALSA: hda: generic: Check potential mixer name string truncation
add_control_with_pfx() constructs a mixer name element with the fixed size, and it got compile warnings with -Wformat-truncation. Although the size overflow is very unlikely, let's have a sanity check of the string size and returns the error if it really doesn't fit instead of silent truncation. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 2832993 commit 5f6af00

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sound/pci/hda/hda_generic.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,11 @@ static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
998998
const char *sfx, int cidx, unsigned long val)
999999
{
10001000
char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
1001-
snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
1001+
int len;
1002+
1003+
len = snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
1004+
if (snd_BUG_ON(len >= sizeof(name)))
1005+
return -EINVAL;
10021006
if (!add_control(spec, type, name, cidx, val))
10031007
return -ENOMEM;
10041008
return 0;

0 commit comments

Comments
 (0)