From nobody Sat May 06 14:42:44 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QD9JP0bfYz49gsJ; Sat, 6 May 2023 14:42:45 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QD9JN75Mnz4NM9; Sat, 6 May 2023 14:42:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683384165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PQKpI432RbKV0My+LqohRLxDQ2Q4vVP1/nA7vOO2laE=; b=DzSGiPc0iXyupkm352SOYNirCmXdlmOtnYRAKXvHFZOOYDRZW/iuH/f95m2wSfBD9ohrql 9mm/vde6q4RIg1/9RmbdXZScLco00IqqGMfYzD+H2crmagdti+3m/8jGDQDkR5dD/lz92r 67Q7RfW/qFmDBkYjmkdr6xYlC3LrTguiYDO4CqS6a07rUmQrhQt0KxMKUzLQ3tjWtpbdE8 PitEU1qyhcEfJSQUeg0S5vLm9IDIss/9oDV7qErVMYl/scB54zyDaS7Z2BeffkOglOG8Nx WtlJRoSm8HG3v+b1nIvHMXx/MXmEMJh3C7Zu3C7iv5j1NqyjqTccrlx+bOI0fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683384165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PQKpI432RbKV0My+LqohRLxDQ2Q4vVP1/nA7vOO2laE=; b=Zda/eBeFi3dB5xHPpekNcr3YtFHAdBVygwyWZyZ2EF2Sv6CKvPf3o5sZJcfC+ch2HIgqfx /G/sutoBMTZEwuzSNVZeRG2IAP928ePyvP2oGi73ems+l9T1ZCYRyREoTY6ufIgbv5oJhL +fpVJqHW7/egkHVPfCi4Ijt3iFO+cobT+vrD9ooZz1uzBcBWtj3WPOjTPk78Fnsn1B4Dg9 ejcRKlr9fSGVP0qzE4n4hgVRqOn8KxcX17jXCQvSB02wx9CveM+QL8lEZn1xhYcBpUiMRg 7QhYjgAxZ99nZ2DlCvlu5CeT5Z00JiUSgKTg+IPdtg+WF+a/v3U9hZGlb+alWw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683384165; a=rsa-sha256; cv=none; b=MKlZoikj+7yfDgg1PGxd96UAv7riS92HFZmX4lGO4xFzs6911jkvhRk2ruTvEP1nOv8kPA KKmP+gCvu3KjAjpATWbDfPG+uw8n+wqfv5dB3XmFjPXeoM2jPE1U07dDv4xjYkkypZ43Ad xbjQ1RQDSUWoiWMZvSLz3ESszVAz+S2UJPEsLdbc09y310w51liD3QZF6xh7Fvvt8KxfO7 QngNIuevyot5Fx48dAVPi4IfDzBSSpmMLfVOXmi4kJZKSaLE2xarcYo7VwuYqwixRN4F3h KwriB1Grwo69RSQ/F4ShG1HSPnjO38qohRqpJTYgOegg0xAg7sKhL5SmyN6dOg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QD9JN6BXMzgJm; Sat, 6 May 2023 14:42:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 346EgiLK020056; Sat, 6 May 2023 14:42:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 346EgitV020055; Sat, 6 May 2023 14:42:44 GMT (envelope-from git) Date: Sat, 6 May 2023 14:42:44 GMT Message-Id: <202305061442.346EgitV020055@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 7c067d5b823d - stable/13 - renice: Avoid segfault if -n flag is given without argument. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7c067d5b823d34d22bbaa9e1f1dd16fdb99fbc2d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=7c067d5b823d34d22bbaa9e1f1dd16fdb99fbc2d commit 7c067d5b823d34d22bbaa9e1f1dd16fdb99fbc2d Author: Dag-Erling Smørgrav AuthorDate: 2023-04-17 19:49:13 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-05-06 13:14:01 +0000 renice: Avoid segfault if -n flag is given without argument. Fixes: 65ee0a8495538 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D39623 (cherry picked from commit b03311cadd3a6f931e176f97b97bd72be3ef96d4) renice: Clean up the tests. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D39629 (cherry picked from commit d59dd30cf19bb6df5635b3c896c7c4262917a9b6) renice: Factor out common code in tests. Furthermore, prefer test -eq (which ignores whitespace) over a strict string equality test when comparing numerical values. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj Differential Revision: https://reviews.freebsd.org/D39650 (cherry picked from commit 1bc6dcc287fa80af74768c4e2b2a1d7511ba1729) --- usr.bin/renice/renice.c | 2 +- usr.bin/renice/tests/renice_test.sh | 92 +++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/usr.bin/renice/renice.c b/usr.bin/renice/renice.c index 890d7043ebbd..42e93cce240e 100644 --- a/usr.bin/renice/renice.c +++ b/usr.bin/renice/renice.c @@ -94,7 +94,7 @@ main(int argc, char *argv[]) } if (strcmp(*argv, "-n") == 0) { /* may occur only once, prior to priority */ - if (haveprio || incr) + if (haveprio || incr || argc < 2) usage(); incr = true; (void)argc--, argv++; diff --git a/usr.bin/renice/tests/renice_test.sh b/usr.bin/renice/tests/renice_test.sh old mode 100644 new mode 100755 index 323fe44591c8..feb07a6af825 --- a/usr.bin/renice/tests/renice_test.sh +++ b/usr.bin/renice/tests/renice_test.sh @@ -1,28 +1,7 @@ -#!/bin/sh -#- -# Copyright (c) 2022 Klara, Inc. -# All rights reserved. # -# 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. +# Copyright (c) 2022-2023 Klara, Inc. # -# 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. +# SPDX-License-Identifier: BSD-2-Clause # # Name of user to use for -u tests when running as root. Beware that @@ -33,8 +12,16 @@ _renice() { atf_check -o empty -e ignore -s exit:0 renice "$@" } -# Set a process's nice number to an absolute value +atf_check_nice_value() { + local pid=$1 + local nice=$2 + atf_check test "$(ps -o nice= -p $pid)" -eq "$nice" +} + atf_test_case renice_abs_pid +renice_abs_pid_head() { + atf_set "descr" "Set a process's nice number to an absolute value" +} renice_abs_pid_body() { local pid nice incr sleep 60 & @@ -42,12 +29,14 @@ renice_abs_pid_body() { nice="$(ps -o nice= -p $pid)" incr=3 _renice $((nice+incr)) $pid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) kill $pid } -# Change a process's nice number by a relative value atf_test_case renice_rel_pid +renice_rel_pid_head() { + atf_set "descr" "Change a process's nice number by a relative value" +} renice_rel_pid_body() { local pid nice incr sleep 60 & @@ -57,12 +46,14 @@ renice_rel_pid_body() { _renice -n $incr $pid _renice -p -n $incr $pid _renice -n $incr -p $pid - atf_check_equal $((nice+incr+incr+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr+incr+incr)) kill $pid } -# Set a process group's nice number to an absolute value atf_test_case renice_abs_pgid +renice_abs_pgid_head() { + atf_set "descr" "Set a process group's nice number to an absolute value" +} renice_abs_pgid_body() { local pid pgid nice incr # make sure target runs in a different pgrp than ours @@ -71,12 +62,14 @@ renice_abs_pgid_body() { nice="$(ps -o nice= -p $pid)" incr=3 _renice $((nice+incr)) -g $pgid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) kill $pid } -# Change a process group's nice number by a relative value atf_test_case renice_rel_pgid +renice_rel_pgid_head() { + atf_set "descr" "Change a process group's nice number by a relative value" +} renice_rel_pgid_body() { local pid pgid nice incr # make sure target runs in a different pgrp than ours @@ -86,13 +79,13 @@ renice_rel_pgid_body() { incr=3 _renice -g -n $incr $pgid _renice -n $incr -g $pgid - atf_check_equal $((nice+incr+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr+incr)) kill $pid } -# Set a user's processes' nice numbers to an absolute value atf_test_case renice_abs_user renice_abs_user_head() { + atf_set "descr" "Set a user's processes' nice numbers to an absolute value" atf_set "require.user" "root" } renice_abs_user_body() { @@ -101,13 +94,13 @@ renice_abs_user_body() { nice="$(ps -o nice= -p $pid)" incr=3 _renice $((nice+incr)) -u $TEST_USER - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) kill $pid } -# Change a user's processes' nice numbers by a relative value atf_test_case renice_rel_user renice_rel_user_head() { + atf_set "descr" "Change a user's processes' nice numbers by a relative value" atf_set "require.user" "root" } renice_rel_user_body() { @@ -117,12 +110,14 @@ renice_rel_user_body() { incr=3 _renice -u -n $incr $TEST_USER _renice -n $incr -u $TEST_USER - atf_check_equal $((nice+incr+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr+incr)) kill $pid } -# Test various delimiter positions atf_test_case renice_delim +renice_delim_head() { + atf_set "descr" "Test various delimiter positions" +} renice_delim_body() { local pid nice incr sleep 60 & @@ -132,32 +127,40 @@ renice_delim_body() { # without -p : $((incr=incr+1)) _renice -- $((nice+incr)) $pid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) : $((incr=incr+1)) _renice $((nice+incr)) -- $pid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) : $((incr=incr+1)) _renice $((nice+incr)) $pid -- - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) # with -p : $((incr=incr+1)) _renice -p -- $((nice+incr)) $pid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) : $((incr=incr+1)) _renice -p $((nice+incr)) -- $pid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) : $((incr=incr+1)) _renice -p $((nice+incr)) $pid -- - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) : $((incr=incr+1)) _renice $((nice+incr)) -p -- $pid - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) : $((incr=incr+1)) _renice $((nice+incr)) -p $pid -- - atf_check_equal $((nice+incr)) "$(ps -o nice= -p $pid)" + atf_check_nice_value $pid $((nice+incr)) kill $pid } +atf_test_case renice_incr_noarg +renice_incr_noarg_head() { + atf_set "descr" "Do not segfault if -n is given without an argument" +} +renice_incr_noarg_body() { + atf_check -o empty -e ignore -s exit:1 renice -n +} + atf_init_test_cases() { atf_add_test_case renice_abs_pid atf_add_test_case renice_rel_pid @@ -166,4 +169,5 @@ atf_init_test_cases() { atf_add_test_case renice_abs_user atf_add_test_case renice_rel_user atf_add_test_case renice_delim + atf_add_test_case renice_incr_noarg }