]> git.alsa-project.org Git - alsa-lib.git/commitdiff
seq: fix snd_seq_parse_address()
authorJaroslav Kysela <perex@perex.cz>
Wed, 26 May 2021 15:28:53 +0000 (17:28 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 26 May 2021 15:29:48 +0000 (17:29 +0200)
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>
src/seq/seqmid.c

index b0f23cb6a1268dfc40a46d6653440c0ee34b5804..75061a577ef31aa95efb0f79a1d26db53903f43c 100644 (file)
@@ -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 */