From b44cb2ca5b56462db5902739e473d34452fbb2fe Mon Sep 17 00:00:00 2001 From: ratchov Date: Fri, 2 Oct 2015 09:48:22 +0000 Subject: Validate that midi and audio device numbers are integers. --- lib/libsndio/debug.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib/libsndio/debug.c') 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 * @@ -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; +} -- cgit v1.2.3-59-g8ed1b