Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Jul 2024 11:56:22 GMT
From:      Christos Margiolis <christos@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 8ca73331ef81 - main - mixer(8): Make mute and recsrc argument parsing more robust
Message-ID:  <202407271156.46RBuMos039801@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=8ca73331ef810cd0e0b9e3c37cddc1d89fbe8c6b

commit 8ca73331ef810cd0e0b9e3c37cddc1d89fbe8c6b
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-07-27 11:55:09 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-07-27 11:55:09 +0000

    mixer(8): Make mute and recsrc argument parsing more robust
    
    For the deprecated argument interfaces of the mute (1, 0, ^) and recsrc
    (+, -, =, ^) controls, we only check the first character of the
    argument, which means that an argument such as "vol.mute=10" would be
    valid. Fix this by checking the whole argument string.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 days
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D45973
---
 usr.sbin/mixer/mixer.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c
index 07dd16536495..109d3ad09bc5 100644
--- a/usr.sbin/mixer/mixer.c
+++ b/usr.sbin/mixer/mixer.c
@@ -426,11 +426,14 @@ mod_mute(struct mix_dev *d, void *p)
 	m = d->parent_mixer;
 	cp = mixer_get_ctl(m->dev, C_MUT);
 	val = p;
-	if (strncmp(val, "off", strlen(val)) == 0 || *val == '0')
+	if (strncmp(val, "off", strlen(val)) == 0 ||
+	    strncmp(val, "0", strlen(val)) == 0)
 		opt = MIX_UNMUTE;
-	else if (strncmp(val, "on", strlen(val)) == 0 || *val == '1')
+	else if (strncmp(val, "on", strlen(val)) == 0 ||
+	    strncmp(val, "1", strlen(val)) == 0)
 		opt = MIX_MUTE;
-	else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^')
+	else if (strncmp(val, "toggle", strlen(val)) == 0 ||
+	    strncmp(val, "^", strlen(val)) == 0)
 		opt = MIX_TOGGLEMUTE;
 	else {
 		warnx("%s: no such modifier", val);
@@ -459,13 +462,17 @@ mod_recsrc(struct mix_dev *d, void *p)
 	m = d->parent_mixer;
 	cp = mixer_get_ctl(m->dev, C_SRC);
 	val = p;
-	if (strncmp(val, "add", strlen(val)) == 0 || *val == '+')
+	if (strncmp(val, "add", strlen(val)) == 0 ||
+	    strncmp(val, "+", strlen(val)) == 0)
 		opt = MIX_ADDRECSRC;
-	else if (strncmp(val, "remove", strlen(val)) == 0 || *val == '-')
+	else if (strncmp(val, "remove", strlen(val)) == 0 ||
+	    strncmp(val, "-", strlen(val)) == 0)
 		opt = MIX_REMOVERECSRC;
-	else if (strncmp(val, "set", strlen(val)) == 0 || *val == '=')
+	else if (strncmp(val, "set", strlen(val)) == 0 ||
+	    strncmp(val, "=", strlen(val)) == 0)
 		opt = MIX_SETRECSRC;
-	else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^')
+	else if (strncmp(val, "toggle", strlen(val)) == 0 ||
+	    strncmp(val, "^", strlen(val)) == 0)
 		opt = MIX_TOGGLERECSRC;
 	else {
 		warnx("%s: no such modifier", val);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407271156.46RBuMos039801>