Skip to content

Commit d278a9d

Browse files
perexgtiwai
authored andcommitted
ALSA: core: add isascii() check to card ID generator
The card identifier should contain only safe ASCII characters. The isalnum() returns true also for characters for non-ASCII characters. Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4135 Link: https://lore.kernel.org/linux-sound/yk3WTvKkwheOon_LzZlJ43PPInz6byYfBzpKkbasww1yzuiMRqn7n6Y8vZcXB-xwFCu_vb8hoNjv7DTNwH5TWjpEuiVsyn9HPCEXqwF4120=@protonmail.com/ Cc: [email protected] Reported-by: Barnabás Pőcze <[email protected]> Signed-off-by: Jaroslav Kysela <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 3302700 commit d278a9d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sound/core/init.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,19 @@ void snd_card_free(struct snd_card *card)
654654
}
655655
EXPORT_SYMBOL(snd_card_free);
656656

657+
/* check, if the character is in the valid ASCII range */
658+
static inline bool safe_ascii_char(char c)
659+
{
660+
return isascii(c) && isalnum(c);
661+
}
662+
657663
/* retrieve the last word of shortname or longname */
658664
static const char *retrieve_id_from_card_name(const char *name)
659665
{
660666
const char *spos = name;
661667

662668
while (*name) {
663-
if (isspace(*name) && isalnum(name[1]))
669+
if (isspace(*name) && safe_ascii_char(name[1]))
664670
spos = name + 1;
665671
name++;
666672
}
@@ -687,12 +693,12 @@ static void copy_valid_id_string(struct snd_card *card, const char *src,
687693
{
688694
char *id = card->id;
689695

690-
while (*nid && !isalnum(*nid))
696+
while (*nid && !safe_ascii_char(*nid))
691697
nid++;
692698
if (isdigit(*nid))
693699
*id++ = isalpha(*src) ? *src : 'D';
694700
while (*nid && (size_t)(id - card->id) < sizeof(card->id) - 1) {
695-
if (isalnum(*nid))
701+
if (safe_ascii_char(*nid))
696702
*id++ = *nid;
697703
nid++;
698704
}
@@ -787,7 +793,7 @@ static ssize_t id_store(struct device *dev, struct device_attribute *attr,
787793

788794
for (idx = 0; idx < copy; idx++) {
789795
c = buf[idx];
790-
if (!isalnum(c) && c != '_' && c != '-')
796+
if (!safe_ascii_char(c) && c != '_' && c != '-')
791797
return -EINVAL;
792798
}
793799
memcpy(buf1, buf, copy);

0 commit comments

Comments
 (0)