summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libsndio/debug.c26
-rw-r--r--lib/libsndio/debug.h3
-rw-r--r--lib/libsndio/mio_rmidi.c11
-rw-r--r--lib/libsndio/sio_sun.c10
4 files changed, 43 insertions, 7 deletions
diff --git a/lib/libsndio/debug.c b/lib/libsndio/debug.c
index e1542bc47cf..6940ca9b909 100644
--- a/lib/libsndio/debug.c
+++ b/lib/libsndio/debug.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: debug.c,v 1.3 2013/11/13 22:38:22 ratchov Exp $ */
+/* $OpenBSD: debug.c,v 1.4 2015/10/02 09:48:22 ratchov Exp $ */
/*
* Copyright (c) 2011 Alexandre Ratchov <alex@caoua.org>
*
@@ -53,3 +53,27 @@ _sndio_parsetype(const char *str, char *type)
return NULL;
return str;
}
+
+const char *
+_sndio_parsenum(const char *str, unsigned int *num, unsigned int max)
+{
+ const char *p = str;
+ unsigned int dig, maxq, maxr, val;
+
+ val = 0;
+ maxq = max / 10;
+ maxr = max % 10;
+ for (;;) {
+ dig = *p - '0';
+ if (dig >= 10)
+ break;
+ if (val > maxq || (val == maxq && dig > maxr))
+ return NULL;
+ val = val * 10 + dig;
+ p++;
+ }
+ if (p == str)
+ return NULL;
+ *num = val;
+ return p;
+}
diff --git a/lib/libsndio/debug.h b/lib/libsndio/debug.h
index 1856159de35..ac8c6398767 100644
--- a/lib/libsndio/debug.h
+++ b/lib/libsndio/debug.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: debug.h,v 1.4 2015/10/02 09:07:09 ratchov Exp $ */
+/* $OpenBSD: debug.h,v 1.5 2015/10/02 09:48:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -47,5 +47,6 @@ extern int _sndio_debug;
#endif
const char *_sndio_parsetype(const char *, char *);
+const char *_sndio_parsenum(const char *, unsigned int *, unsigned int);
#endif
diff --git a/lib/libsndio/mio_rmidi.c b/lib/libsndio/mio_rmidi.c
index 9e8c3cae8bc..53f92d9e551 100644
--- a/lib/libsndio/mio_rmidi.c
+++ b/lib/libsndio/mio_rmidi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_rmidi.c,v 1.18 2015/10/02 09:45:26 ratchov Exp $ */
+/* $OpenBSD: mio_rmidi.c,v 1.19 2015/10/02 09:48:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -62,6 +62,7 @@ _mio_rmidi_open(const char *str, unsigned int mode, int nbio)
int fd, flags;
struct mio_rmidi_hdl *hdl;
char path[DEVPATH_MAX];
+ unsigned int devnum;
switch (*str) {
case '/':
@@ -71,12 +72,16 @@ _mio_rmidi_open(const char *str, unsigned int mode, int nbio)
DPRINTF("_mio_rmidi_open: %s: '/<devnum>' expected\n", str);
return NULL;
}
+ str = _sndio_parsenum(str, &devnum, 255);
+ if (str == NULL || *str != '\0') {
+ DPRINTF("_mio_rmidi_open: can't determine device number\n");
+ return NULL;
+ }
hdl = malloc(sizeof(struct mio_rmidi_hdl));
if (hdl == NULL)
return NULL;
_mio_create(&hdl->mio, &mio_rmidi_ops, mode, nbio);
-
- snprintf(path, sizeof(path), DEVPATH_PREFIX "%s", str);
+ snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum);
if (mode == (MIO_OUT | MIO_IN))
flags = O_RDWR;
else
diff --git a/lib/libsndio/sio_sun.c b/lib/libsndio/sio_sun.c
index f7deb774996..9a637722c13 100644
--- a/lib/libsndio/sio_sun.c
+++ b/lib/libsndio/sio_sun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio_sun.c,v 1.18 2015/10/02 09:45:26 ratchov Exp $ */
+/* $OpenBSD: sio_sun.c,v 1.19 2015/10/02 09:48:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -336,6 +336,7 @@ _sio_sun_open(const char *str, unsigned int mode, int nbio)
struct sio_sun_hdl *hdl;
struct sio_par par;
char path[DEVPATH_MAX];
+ unsigned int devnum;
switch (*str) {
case '/':
@@ -345,12 +346,17 @@ _sio_sun_open(const char *str, unsigned int mode, int nbio)
DPRINTF("_sio_sun_open: %s: '/<devnum>' expected\n", str);
return NULL;
}
+ str = _sndio_parsenum(str, &devnum, 255);
+ if (str == NULL || *str != '\0') {
+ DPRINTF("_sio_sun_open: can't determine device number\n");
+ return NULL;
+ }
hdl = malloc(sizeof(struct sio_sun_hdl));
if (hdl == NULL)
return NULL;
_sio_create(&hdl->sio, &sio_sun_ops, mode, nbio);
- snprintf(path, sizeof(path), DEVPATH_PREFIX "%s", str);
+ snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum);
if (mode == (SIO_PLAY | SIO_REC))
flags = O_RDWR;
else