Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: core: add isascii() check to card ID generator
@ 2024-10-02 19:46 Jaroslav Kysela
  2024-10-03  7:18 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Jaroslav Kysela @ 2024-10-02 19:46 UTC (permalink / raw)
  To: Linux Sound ML
  Cc: Takashi Iwai, Jaroslav Kysela, stable, Barnabás Pőcze

The card identifier should contain only safe ASCII characters. The isalnum()
returns true also for characters for non-ASCII characters.

Buglink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4135
Link: https://lore.kernel.org/linux-sound/yk3WTvKkwheOon_LzZlJ43PPInz6byYfBzpKkbasww1yzuiMRqn7n6Y8vZcXB-xwFCu_vb8hoNjv7DTNwH5TWjpEuiVsyn9HPCEXqwF4120=@protonmail.com/
Cc: stable@vger.kernel.org
Reported-by: Barnabás Pőcze <pobrn@protonmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 sound/core/init.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sound/core/init.c b/sound/core/init.c
index b92aa7103589..114fb87de990 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -654,13 +654,19 @@ void snd_card_free(struct snd_card *card)
 }
 EXPORT_SYMBOL(snd_card_free);
 
+/* check, if the character is in the valid ASCII range */
+static inline bool safe_ascii_char(char c)
+{
+	return isascii(c) && isalnum(c);
+}
+
 /* retrieve the last word of shortname or longname */
 static const char *retrieve_id_from_card_name(const char *name)
 {
 	const char *spos = name;
 
 	while (*name) {
-		if (isspace(*name) && isalnum(name[1]))
+		if (isspace(*name) && safe_ascii_char(name[1]))
 			spos = name + 1;
 		name++;
 	}
@@ -687,12 +693,12 @@ static void copy_valid_id_string(struct snd_card *card, const char *src,
 {
 	char *id = card->id;
 
-	while (*nid && !isalnum(*nid))
+	while (*nid && !safe_ascii_char(*nid))
 		nid++;
 	if (isdigit(*nid))
 		*id++ = isalpha(*src) ? *src : 'D';
 	while (*nid && (size_t)(id - card->id) < sizeof(card->id) - 1) {
-		if (isalnum(*nid))
+		if (safe_ascii_char(*nid))
 			*id++ = *nid;
 		nid++;
 	}
@@ -787,7 +793,7 @@ static ssize_t id_store(struct device *dev, struct device_attribute *attr,
 
 	for (idx = 0; idx < copy; idx++) {
 		c = buf[idx];
-		if (!isalnum(c) && c != '_' && c != '-')
+		if (!safe_ascii_char(c) && c != '_' && c != '-')
 			return -EINVAL;
 	}
 	memcpy(buf1, buf, copy);
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: core: add isascii() check to card ID generator
  2024-10-02 19:46 [PATCH] ALSA: core: add isascii() check to card ID generator Jaroslav Kysela
@ 2024-10-03  7:18 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-10-03  7:18 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: Linux Sound ML, Takashi Iwai, stable, Barnabás Pőcze

On Wed, 02 Oct 2024 21:46:49 +0200,
Jaroslav Kysela wrote:
> 
> The card identifier should contain only safe ASCII characters. The isalnum()
> returns true also for characters for non-ASCII characters.
> 
> Buglink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4135
> Link: https://lore.kernel.org/linux-sound/yk3WTvKkwheOon_LzZlJ43PPInz6byYfBzpKkbasww1yzuiMRqn7n6Y8vZcXB-xwFCu_vb8hoNjv7DTNwH5TWjpEuiVsyn9HPCEXqwF4120=@protonmail.com/
> Cc: stable@vger.kernel.org
> Reported-by: Barnabás Pőcze <pobrn@protonmail.com>
> Signed-off-by: Jaroslav Kysela <perex@perex.cz>

Applied now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-03  7:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 19:46 [PATCH] ALSA: core: add isascii() check to card ID generator Jaroslav Kysela
2024-10-03  7:18 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox