From owner-svn-src-all@freebsd.org Sun Aug 25 17:55:33 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6E3CBE490D; Sun, 25 Aug 2019 17:55:33 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46GjTx2Htzz4Bgg; Sun, 25 Aug 2019 17:55:33 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 163D721348; Sun, 25 Aug 2019 17:55:33 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7PHtWF3068495; Sun, 25 Aug 2019 17:55:32 GMT (envelope-from 0mp@FreeBSD.org) Received: (from 0mp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7PHtWNF068489; Sun, 25 Aug 2019 17:55:32 GMT (envelope-from 0mp@FreeBSD.org) Message-Id: <201908251755.x7PHtWNF068489@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: 0mp set sender to 0mp@FreeBSD.org using -f From: Mateusz Piotrowski <0mp@FreeBSD.org> Date: Sun, 25 Aug 2019 17:55:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351481 - in head: etc/mtree usr.sbin/mixer usr.sbin/mixer/tests X-SVN-Group: head X-SVN-Commit-Author: 0mp X-SVN-Commit-Paths: in head: etc/mtree usr.sbin/mixer usr.sbin/mixer/tests X-SVN-Commit-Revision: 351481 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Aug 2019 17:55:33 -0000 Author: 0mp (ports committer) Date: Sun Aug 25 17:55:31 2019 New Revision: 351481 URL: https://svnweb.freebsd.org/changeset/base/351481 Log: mixer(8): Report an error if the passed value is an empty string This patch fixes a bug that made the mixer command enter an infinite loop when instructed to set the value of a device to an empty string (e.g., `mixer vol ""`). Additionally, some tests for mixer(8) are being added. PR: 240039 Reviewed by: hselasky, mav Approved by: src (hselasky, mav) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D21409 Added: head/usr.sbin/mixer/tests/ head/usr.sbin/mixer/tests/Makefile (contents, props changed) head/usr.sbin/mixer/tests/mixer_test.sh (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/usr.sbin/mixer/Makefile head/usr.sbin/mixer/mixer.c Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Sun Aug 25 17:13:00 2019 (r351480) +++ head/etc/mtree/BSD.tests.dist Sun Aug 25 17:55:31 2019 (r351481) @@ -821,6 +821,8 @@ .. link .. + mixer + .. mkdir .. mkfifo Modified: head/usr.sbin/mixer/Makefile ============================================================================== --- head/usr.sbin/mixer/Makefile Sun Aug 25 17:13:00 2019 (r351480) +++ head/usr.sbin/mixer/Makefile Sun Aug 25 17:55:31 2019 (r351481) @@ -1,6 +1,11 @@ # $FreeBSD$ +.include + PROG= mixer MAN= mixer.8 + +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests .include Modified: head/usr.sbin/mixer/mixer.c ============================================================================== --- head/usr.sbin/mixer/mixer.c Sun Aug 25 17:13:00 2019 (r351480) +++ head/usr.sbin/mixer/mixer.c Sun Aug 25 17:55:31 2019 (r351481) @@ -241,6 +241,11 @@ main(int argc, char *argv[]) lrel = rrel = 0; if (argc > 1) { m = sscanf(argv[1], "%7[^:]:%7s", lstr, rstr); + if (m == EOF) { + warnx("invalid value: %s", argv[1]); + dusage = 1; + break; + } if (m > 0) { if (*lstr == '+' || *lstr == '-') lrel = rrel = 1; Added: head/usr.sbin/mixer/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/mixer/tests/Makefile Sun Aug 25 17:55:31 2019 (r351481) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +ATF_TESTS_SH+= mixer_test + +.include Added: head/usr.sbin/mixer/tests/mixer_test.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/mixer/tests/mixer_test.sh Sun Aug 25 17:55:31 2019 (r351481) @@ -0,0 +1,123 @@ +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Mateusz Piotrowski <0mp@FreeBSD.org> +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +# $FreeBSD$ + +mixer_unavailable() +{ + ! { mixer && mixer vol; } >/dev/null 2>&1 +} + +save_mixer_vol() +{ + atf_check -o match:'^[0-9]{1,3}:[0-9]{1,3}$' -o save:saved_vol \ + -x "mixer vol | awk '{print \$7}'" +} + +set_mixer_vol() +{ + atf_check \ + -o match:'^Setting the mixer vol from [0-9]{1,3}:[0-9]{1,3} to 0:0\.$' \ + mixer vol 0 +} + +restore_mixer_vol() +{ + if [ -r "saved_vol" ]; then + mixer vol "$(cat saved_vol)" + fi +} + +atf_test_case s_flag cleanup +s_flag_head() +{ + atf_set "descr" "Verify that the output of the -s flag could be " \ + "reused as command-line arguments to the mixer command" +} +s_flag_body() +{ + if mixer_unavailable; then + atf_skip "This test requires mixer support" + fi + save_mixer_vol + set_mixer_vol + atf_check -o inline:"vol 0:0" -o save:values mixer -s vol + atf_check -o inline:"Setting the mixer vol from 0:0 to 0:0.\n" \ + mixer $(cat values) +} +s_flag_cleanup() +{ + restore_mixer_vol +} + +atf_test_case S_flag cleanup +S_flag_head() +{ + atf_set "descr" "Verify that the output of the -S flag is " \ + "matching the documented behavior" +} +S_flag_body() +{ + if mixer_unavailable; then + atf_skip "This test requires mixer support" + fi + save_mixer_vol + set_mixer_vol + atf_check -o inline:"vol:0:0" mixer -S vol +} +S_flag_cleanup() +{ + restore_mixer_vol +} + +atf_test_case set_empty_value +set_empty_value_head() +{ + atf_set "descr" "Verify that mixer returns when the provided " \ + "value to set is an empty string instead of a number" + atf_set "timeout" "1" +} +set_empty_value_body() +{ + if mixer_unavailable; then + atf_skip "This test requires mixer support" + fi + save_mixer_vol + atf_check -s exit:1 -e inline:"mixer: invalid value: \n" \ + -o match:"^usage:" mixer vol "" +} +set_empty_value_cleanup() +{ + restore_mixer_vol +} + + +atf_init_test_cases() +{ + atf_add_test_case s_flag + atf_add_test_case S_flag + atf_add_test_case set_empty_value +}