git: bf3d523408d4 - stable/14 - mixer(8): Make mute and recsrc argument parsing more robust

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Mon, 29 Jul 2024 15:35:19 UTC
The branch stable/14 has been updated by christos:

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

commit bf3d523408d48126e83a097978e2db469954d238
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-07-27 11:55:09 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-07-29 15:34:54 +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
    
    (cherry picked from commit 8ca73331ef810cd0e0b9e3c37cddc1d89fbe8c6b)
---
 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);