mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-05 04:06:34 -05:00
control: ctlparse - make numid parsing more robust
Also correct the last amixer stderr printf to snd_error(). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
7887fbc6f0
commit
bc332f4211
1 changed files with 18 additions and 6 deletions
|
|
@ -156,8 +156,10 @@ char *snd_ctl_ascii_elem_id_get(snd_ctl_elem_id_t *id)
|
|||
int __snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str,
|
||||
const char **ret_ptr)
|
||||
{
|
||||
int c, size, numid;
|
||||
char buf[64];
|
||||
int c, size;
|
||||
int err = -EINVAL;
|
||||
long l;
|
||||
char *ptr;
|
||||
|
||||
while (isspace(*str))
|
||||
|
|
@ -168,12 +170,23 @@ int __snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str,
|
|||
while (*str) {
|
||||
if (!strncasecmp(str, "numid=", 6)) {
|
||||
str += 6;
|
||||
numid = atoi(str);
|
||||
if (numid <= 0) {
|
||||
fprintf(stderr, "amixer: Invalid numid %d\n", numid);
|
||||
ptr = buf;
|
||||
size = 0;
|
||||
while (*str && *str != ',') {
|
||||
if (size < (int)sizeof(buf)) {
|
||||
*ptr++ = *str;
|
||||
size++;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
*ptr = '\0';
|
||||
if (safe_strtol(buf, &l) < 0)
|
||||
l = -1;
|
||||
if (l <= 0 || l >= INT32_MAX) {
|
||||
snd_error(CONTROL, "Invalid numid %ld (%s)", l, buf);
|
||||
goto out;
|
||||
}
|
||||
snd_ctl_elem_id_set_numid(dst, atoi(str));
|
||||
snd_ctl_elem_id_set_numid(dst, (int)l);
|
||||
while (isdigit(*str))
|
||||
str++;
|
||||
} else if (!strncasecmp(str, "iface=", 6)) {
|
||||
|
|
@ -200,7 +213,6 @@ int __snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str,
|
|||
goto out;
|
||||
}
|
||||
} else if (!strncasecmp(str, "name=", 5)) {
|
||||
char buf[64];
|
||||
str += 5;
|
||||
ptr = buf;
|
||||
size = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue