summaryrefslogtreecommitdiffstats
path: root/lib/libsndio/debug.c
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2015-10-02 09:48:22 +0000
committerratchov <ratchov@openbsd.org>2015-10-02 09:48:22 +0000
commitb44cb2ca5b56462db5902739e473d34452fbb2fe (patch)
tree8c280c87d6e200075a2b92248476becc6b35a83a /lib/libsndio/debug.c
parentAs device path is known, use its size instead of PATH_MAX (diff)
downloadwireguard-openbsd-b44cb2ca5b56462db5902739e473d34452fbb2fe.tar.xz
wireguard-openbsd-b44cb2ca5b56462db5902739e473d34452fbb2fe.zip
Validate that midi and audio device numbers are integers.
Diffstat (limited to 'lib/libsndio/debug.c')
-rw-r--r--lib/libsndio/debug.c26
1 files changed, 25 insertions, 1 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;
+}