mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-31 22:25:35 -04:00
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 <perex@perex.cz>
This commit is contained in:
parent
aa70b19d4c
commit
c8f608d674
1 changed files with 30 additions and 12 deletions
|
|
@ -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)
|
int snd_seq_parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, const char *arg)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p, *buf;
|
||||||
int client, port;
|
const char *s;
|
||||||
|
char c;
|
||||||
|
long client, port = 0;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
assert(addr && arg);
|
assert(addr && arg);
|
||||||
|
|
||||||
if ((p = strpbrk(arg, ":.")) != NULL) {
|
c = *arg;
|
||||||
if ((port = atoi(p + 1)) < 0)
|
if (c == '"' || c == '\'') {
|
||||||
return -EINVAL;
|
s = ++arg;
|
||||||
len = (int)(p - arg); /* length of client name */
|
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 {
|
} else {
|
||||||
port = 0;
|
if ((p = strpbrk(arg, ":.")) != NULL) {
|
||||||
len = strlen(arg);
|
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;
|
addr->port = port;
|
||||||
if (isdigit(*arg)) {
|
if (safe_strtol(buf, &client) == 0) {
|
||||||
client = atoi(arg);
|
|
||||||
if (client < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
addr->client = client;
|
addr->client = client;
|
||||||
} else {
|
} else {
|
||||||
/* convert from the name */
|
/* convert from the name */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue