Replace unsafe characters with _ in card name
PATCH 1/1 Replace unsafe characters with _ in card name
Otherwise, they get misinterpreted as argument separators in USB-Audio PCM definitions, and thus prevent SPDIF blacklist entries from working.
While at it, add my Logitec C910 webcam to the SPDIF blacklist.
---
I did not send this patch earlier because of hesitation whether to send it as it is or to implement proper escaping, and then forgot about it.
include/conf.h | 1 + src/conf.c | 32 ++++++++++++++++++++++++++++++++ src/conf/cards/USB-Audio.conf | 3 ++- src/confmisc.c | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-)
include/conf.h +1 -0
@@ -126,6 +126,7 @@ int snd_config_imake_integer(snd_config_t **config, const char *key, const longint snd_config_imake_integer64 (snd_config_t **config,const char *key,const long long value);int snd_config_imake_real (snd_config_t **config,const char *key,const double value);int snd_config_imake_string (snd_config_t **config,const char *key,const char *ascii); +int snd_config_imake_safe_string (snd_config_t **config,const char *key,const char *ascii);int snd_config_imake_pointer (snd_config_t **config,const char *key,const void *ptr);snd_config_type_t snd_config_get_type (const snd_config_t *config);
src/conf.c +32 -0
@@ -2228,6 +2228,38 @@ int snd_config_imake_string(snd_config_t **config, const char *id, const char *vreturn 0 ; } +int snd_config_imake_safe_string (snd_config_t **config,const char *id,const char *value) +{ +int err; +snd_config_t *tmp; +char *c; + + err =snd_config_make (&tmp, id,SND_CONFIG_TYPE_STRING ); +if (err <0 ) +return err; +if (value) { + tmp->u.string =strdup (value); +for (c = tmp->u.string; *c; c++) { +if (*c ==' ' || *c =='-' || *c =='_' || + (*c >='0' && *c <='9' ) || + (*c >='a' && *c <='z' ) || + (*c >='A' && *c <='Z' )) +continue ; + *c ='_' ; + } + +if (!tmp->u.string) { +snd_config_delete (tmp); +return -ENOMEM ; + } + }else { + tmp->u.string =NULL ; + } + *config = tmp; +return 0 ; +} + +/** * \brief Creates a pointer configuration node with the given initial value. * \param[out] config The function puts the handle to the new node at
src/conf/cards/USB-Audio.conf +2 -1
@@ -57,7 +57,8 @@ USB-Audio.pcm.iec958_device { "Scarlett 2i4 USB" 999 "Sennheiser USB headset" 999 "SWTOR Gaming Headset by Razer" 999 - "USB Device 0x46d:0x992" 999 + "USB Device 0x46d_0x821" 999 + "USB Device 0x46d_0x992" 999 } # Second iec958 device number, if any.
src/confmisc.c +1 -1
@@ -935,7 +935,7 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root, } err =snd_config_get_id (src, &id);if (err >=0 ) - err =snd_config_imake_string (dst, id, + err =snd_config_imake_safe_string (dst, id,snd_ctl_card_info_get_name (info)); __error:if (ctl)
Signature · 1 line
2.4.4
At Sat, 27 Jun 2015 19:32:49 +0500,
Quoted 11 lines · Alexander E. Patrakov
Otherwise, they get misinterpreted as argument separators in USB-Audio PCM definitions, and thus prevent SPDIF blacklist entries from working.
While at it, add my Logitec C910 webcam to the SPDIF blacklist.
Signed-off-by Alexander E. Patrakov <[email protected]>---
I did not send this patch earlier because of hesitation whether to send it as it is or to implement proper escaping, and then forgot about it.
I find the idea is fine. Just small nitpicking:
Quoted 27 lines
include/conf.h | 1 + src/conf.c | 32 ++++++++++++++++++++++++++++++++ src/conf/cards/USB-Audio.conf | 3 ++- src/confmisc.c | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-)include/conf.h +1
-0@@ -126,6 +126,7 @@ int snd_config_imake_integer(snd_config_t **config, const char *key, const longint snd_config_imake_integer64 (snd_config_t **config,const char *key,const long long value);int snd_config_imake_real (snd_config_t **config,const char *key,const double value);int snd_config_imake_string (snd_config_t **config,const char *key,const char *ascii); +int snd_config_imake_safe_string (snd_config_t **config,const char *key,const char *ascii);int snd_config_imake_pointer (snd_config_t **config,const char *key,const void *ptr);snd_config_type_t snd_config_get_type (const snd_config_t *config);src/conf.c +1
-0@@ -2228,6 +2228,38 @@ int snd_config_imake_string(snd_config_t **config, const char *id, const char *vreturn 0 ; } +int snd_config_imake_safe_string (snd_config_t **config,const char *id,const char *value)
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2241
Quoted 10 lines
src/conf.c +10
-0+{ +int err; +snd_config_t *tmp; +char *c; + + err =snd_config_make (&tmp, id,SND_CONFIG_TYPE_STRING ); +if (err <0 ) +return err; +if (value) { + tmp->u.string =strdup (value);
The NULL check is put in a wrong place.
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2247
Quoted 6 lines
src/conf.c +6
-0+for (c = tmp->u.string; *c; c++) { +if (*c ==' ' || *c =='-' || *c =='_' || + (*c >='0' && *c <='9' ) || + (*c >='a' && *c <='z' ) || + (*c >='A' && *c <='Z' )) +continue ;
Can the last three be isalnum()?
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2254
Quoted 7 lines
src/conf.c +7
-0+ *c ='_' ; + } + +if (!tmp->u.string) { +snd_config_delete (tmp); +return -ENOMEM ; + }
This should be before conversion.
thanks,
Takashi
Quoted 41 lines
src/conf.c +8
-0+ }else { + tmp->u.string =NULL ; + } + *config = tmp; +return 0 ; +} + +/** * \brief Creates a pointer configuration node with the given initial value. * \param[out] config The function puts the handle to the new node at src/conf/cards/USB-Audio.conf +2
-1@@ -57,7 +57,8 @@ USB-Audio.pcm.iec958_device { "Scarlett 2i4 USB" 999 "Sennheiser USB headset" 999 "SWTOR Gaming Headset by Razer" 999 - "USB Device 0x46d:0x992" 999 + "USB Device 0x46d_0x821" 999 + "USB Device 0x46d_0x992" 999 } # Second iec958 device number, if any.src/confmisc.c +1
-1@@ -935,7 +935,7 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root, } err =snd_config_get_id (src, &id);if (err >=0 ) - err =snd_config_imake_string (dst, id, + err =snd_config_imake_safe_string (dst, id,snd_ctl_card_info_get_name (info)); __error:if (ctl)Signature · 1 line
2.4.4
Quoted 7 lines · Takashi Iwai
At Sat, 27 Jun 2015 19:32:49 +0500,
Quoted 5 lines · Alexander E. Patrakov
Otherwise, they get misinterpreted as argument separators in USB-Audio PCM definitions, and thus prevent SPDIF blacklist entries from working.
Quoted 8 lines
Quoted 6 lines
While at it, add my Logitec C910 webcam to the SPDIF blacklist.
Signed-off-by Alexander E. Patrakov <[email protected]>---
I did not send this patch earlier because of hesitation whether to send it as it is or to implement proper escaping, and then forgot about it.I find the idea is fine. Just small nitpicking:
Thanks for the review, I will send a new version soon.
Quoted 28 lines
Quoted 28 lines
include/conf.h | 1 + src/conf.c | 32 ++++++++++++++++++++++++++++++++ src/conf/cards/USB-Audio.conf | 3 ++- src/confmisc.c | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-)include/conf.h +1
-0@@ -126,6 +126,7 @@ int snd_config_imake_integer(snd_config_t **config, const char *key, const longint snd_config_imake_integer64 (snd_config_t **config,const char *key,const long long value);int snd_config_imake_real (snd_config_t **config,const char *key,const double value);int snd_config_imake_string (snd_config_t **config,const char *key,const char *ascii); +int snd_config_imake_safe_string (snd_config_t **config,const char *key,const char *ascii);int snd_config_imake_pointer (snd_config_t **config,const char *key,const void *ptr);snd_config_type_t snd_config_get_type (const snd_config_t *config);src/conf.c +0
-0@@ -2228,6 +2228,38 @@ int snd_config_imake_string(snd_config_t **config, const char *id, const char *vreturn 0 ; }
Quoted 13 lines
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2241
Quoted 11 lines
src/conf.c +11
-0+int snd_config_imake_safe_string (snd_config_t **config,const char *id,const char *value) +{ +int err; +snd_config_t *tmp; +char *c; + + err =snd_config_make (&tmp, id,SND_CONFIG_TYPE_STRING ); +if (err <0 ) +return err; +if (value) { + tmp->u.string =strdup (value);The NULL check is put in a wrong place.
I don't see what's wrong, could you please elaborate? And if this is wrong, then snd_config_imake_string() has the same bug.
Quoted 9 lines
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2247
Quoted 7 lines
src/conf.c +6
-0+for (c = tmp->u.string; *c; c++) { +if (*c ==' ' || *c =='-' || *c =='_' || + (*c >='0' && *c <='9' ) || + (*c >='a' && *c <='z' ) || + (*c >='A' && *c <='Z' )) +continue ;Can the last three be
isalnum()?
No. isalnum() is locale-dependent.
Quoted 10 lines
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2254
Quoted 8 lines
src/conf.c +7
-0+ *c ='_' ; + } + +if (!tmp->u.string) { +snd_config_delete (tmp); +return -ENOMEM ; + }This should be before conversion.
Oops...
Signature · 1 line
Alexander E. Patrakov
At Mon, 29 Jun 2015 22:44:47 +0500,
Quoted 62 lines · Alexander E. Patrakov
Quoted 7 lines · Takashi Iwai
At Sat, 27 Jun 2015 19:32:49 +0500,
Quoted 5 lines · Alexander E. Patrakov
Otherwise, they get misinterpreted as argument separators in USB-Audio PCM definitions, and thus prevent SPDIF blacklist entries from working.
Quoted 8 lines
Quoted 6 lines
While at it, add my Logitec C910 webcam to the SPDIF blacklist.
Signed-off-by Alexander E. Patrakov <[email protected]>---
I did not send this patch earlier because of hesitation whether to send it as it is or to implement proper escaping, and then forgot about it.I find the idea is fine. Just small nitpicking:
Thanks for the review, I will send a new version soon.
Quoted 28 lines
Quoted 28 lines
include/conf.h | 1 + src/conf.c | 32 ++++++++++++++++++++++++++++++++ src/conf/cards/USB-Audio.conf | 3 ++- src/confmisc.c | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-)include/conf.h +1
-0@@ -126,6 +126,7 @@ int snd_config_imake_integer(snd_config_t **config, const char *key, const longint snd_config_imake_integer64 (snd_config_t **config,const char *key,const long long value);int snd_config_imake_real (snd_config_t **config,const char *key,const double value);int snd_config_imake_string (snd_config_t **config,const char *key,const char *ascii); +int snd_config_imake_safe_string (snd_config_t **config,const char *key,const char *ascii);int snd_config_imake_pointer (snd_config_t **config,const char *key,const void *ptr);snd_config_type_t snd_config_get_type (const snd_config_t *config);src/conf.c +0
-0@@ -2228,6 +2228,38 @@ int snd_config_imake_string(snd_config_t **config, const char *id, const char *vreturn 0 ; }Quoted 13 lines
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2241
Quoted 11 lines
src/conf.c +11
-0+int snd_config_imake_safe_string (snd_config_t **config,const char *id,const char *value) +{ +int err; +snd_config_t *tmp; +char *c; + + err =snd_config_make (&tmp, id,SND_CONFIG_TYPE_STRING ); +if (err <0 ) +return err; +if (value) { + tmp->u.string =strdup (value);The NULL check is put in a wrong place.
Quoted 1 line
I don't see what's wrong, could you please elaborate?
The check of strdup() is done after accessing tmp->u.string.
Quoted 13 lines
And if this is
wrong, thensnd_config_imake_string()has the same bug.Quoted 9 lines
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2247
Quoted 7 lines
src/conf.c +6
-0+for (c = tmp->u.string; *c; c++) { +if (*c ==' ' || *c =='-' || *c =='_' || + (*c >='0' && *c <='9' ) || + (*c >='a' && *c <='z' ) || + (*c >='A' && *c <='Z' )) +continue ;Can the last three be
isalnum()?
Quoted 1 line
No.
isalnum()is locale-dependent.
Hm, OK, then we should keep open-coded.
thanks,
Takashi
Quoted 16 lines
Quoted 10 lines
src/conf.c int snd_config_imake_string(snd_config_t **config, const char *id, const char *v · line 2254
Quoted 8 lines
src/conf.c +7
-0+ *c ='_' ; + } + +if (!tmp->u.string) { +snd_config_delete (tmp); +return -ENOMEM ; + }This should be before conversion.
Oops...
Signature · 1 line
Alexander E. Patrakov