From c8f20fb97f0aeab038932e2fa0cf3f5a03b8c10a Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Tue, 8 Nov 2011 09:32:00 +0100 Subject: [PATCH] make devnum mandatory --- aucat/opt.c | 6 ++---- libsndio/aucat.c | 40 ++++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/aucat/opt.c b/aucat/opt.c index 259a595..3abebbc 100644 --- a/aucat/opt.c +++ b/aucat/opt.c @@ -42,10 +42,8 @@ opt_new(char *name, struct dev *dev, exit(1); } c = name[len]; - if (c < 'a' && c > 'z' && - c < 'A' && c > 'Z' && - c < '0' && c > '9' && - c != '_') { + if ((c < 'a' || c > 'z') && + (c < 'A' || c > 'Z')) { fprintf(stderr, "%s: '%c' not allowed\n", name, c); exit(1); } diff --git a/libsndio/aucat.c b/libsndio/aucat.c index 37182e6..4fab748 100644 --- a/libsndio/aucat.c +++ b/libsndio/aucat.c @@ -411,10 +411,6 @@ parsedev(const char *str, unsigned *rval) const char *p = str; unsigned val; - if (*p < '0' || *p > '9') { - DPRINTF("%s: number expected\n", str); - return NULL; - } for (val = 0; *p >= '0' && *p <= '9'; p++) { val = 10 * val + (*p - '0'); if (val >= 16) { @@ -422,6 +418,10 @@ parsedev(const char *str, unsigned *rval) return NULL; } } + if (p == str) { + DPRINTF("%s: number expected\n", str); + return NULL; + } *rval = val; return p; } @@ -431,13 +431,17 @@ parsestr(const char *str, char *rstr, unsigned max) { const char *p = str; - while (*p != '\0' && *p != ',') { + while (*p != '\0' && *p != ',' && *p != '/') { if (--max == 0) { - DPRINTF("%s: too long\n", str); - return 0; + DPRINTF("%s: string too long\n", str); + return NULL; } *rstr++ = *p++; } + if (str == p) { + DPRINTF("%s: string expected\n", str); + return NULL; + } *rstr = '\0'; return p; } @@ -448,30 +452,28 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, unsigned type) extern char *__progname; int eof; char host[NI_MAXHOST], opt[AMSG_OPTMAX]; - const char *p; + const char *p = str; unsigned unit, devnum; - p = str; if (*p == '@') { p = parsestr(++p, host, NI_MAXHOST); if (p == NULL) return 0; } else - host[0] = '\0'; + *host = '\0'; if (*p == ',') { p = parsedev(++p, &unit); if (p == NULL) return 0; } else unit = 0; - if (*p == '/' || *p == ':') { - p = parsedev(++p, &devnum); - if (p == NULL) - return 0; - } else - devnum = 0; - if (type) - devnum += 16; /* XXX */ + if (*p != '/' && *p != ':') { + DPRINTF("%s: '/' expected\n", str); + return 0; + } + p = parsedev(++p, &devnum); + if (p == NULL) + return 0; if (*p == '.') { p = parsestr(++p, opt, AMSG_OPTMAX); if (p == NULL) @@ -482,6 +484,8 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, unsigned type) DPRINTF("%s: junk at end of dev name\n", p); return 0; } + if (type) + devnum += 16; /* XXX */ DPRINTF("aucat_open: host=%s unit=%u devnum=%u opt=%s\n", host, unit, devnum, opt); if (host[0] != '\0') {