From: Jaroslav Kysela Date: Wed, 26 May 2021 15:28:53 +0000 (+0200) Subject: seq: fix snd_seq_parse_address() X-Git-Tag: v1.2.5~3 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=c8f608d67463b814f2c077c3cdae5663f3574f12;p=alsa-lib.git seq: fix snd_seq_parse_address() Use safe_strtol() for the integer conversion. Also accept client name in "" or '' notation. BugLink: https://github.com/alsa-project/alsa-utils/issues/90 Signed-off-by: Jaroslav Kysela --- diff --git a/src/seq/seqmid.c b/src/seq/seqmid.c index b0f23cb6..75061a57 100644 --- a/src/seq/seqmid.c +++ b/src/seq/seqmid.c @@ -388,25 +388,43 @@ int snd_seq_sync_output_queue(snd_seq_t *seq) */ int snd_seq_parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, const char *arg) { - char *p; - int client, port; + char *p, *buf; + const char *s; + char c; + long client, port = 0; int len; assert(addr && arg); - if ((p = strpbrk(arg, ":.")) != NULL) { - if ((port = atoi(p + 1)) < 0) - return -EINVAL; - len = (int)(p - arg); /* length of client name */ + c = *arg; + if (c == '"' || c == '\'') { + s = ++arg; + while (*s && *s != c) s++; + len = s - arg; + if (*s) + s++; + if (*s) { + if (*s != '.' && *s != ':') + return -EINVAL; + if ((port = atoi(s + 1)) < 0) + return -EINVAL; + } } else { - port = 0; - len = strlen(arg); + if ((p = strpbrk(arg, ":.")) != NULL) { + if ((port = atoi(p + 1)) < 0) + return -EINVAL; + len = (int)(p - arg); /* length of client name */ + } else { + len = strlen(arg); + } } + if (len == 0) + return -EINVAL; + buf = alloca(len + 1); + strncpy(buf, arg, len); + buf[len] = '\0'; addr->port = port; - if (isdigit(*arg)) { - client = atoi(arg); - if (client < 0) - return -EINVAL; + if (safe_strtol(buf, &client) == 0) { addr->client = client; } else { /* convert from the name */