From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3437A15800F for ; Tue, 14 Feb 2023 03:40:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 022E9E079E; Tue, 14 Feb 2023 03:40:32 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D9F9EE079E for ; Tue, 14 Feb 2023 03:40:31 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (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) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DC0D3335DB5 for ; Tue, 14 Feb 2023 03:40:30 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2BC488A7 for ; Tue, 14 Feb 2023 03:40:29 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1676345989.e650022a1291ab98efd2af02a4c83c395e2d5fa1.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: e650022a1291ab98efd2af02a4c83c395e2d5fa1 X-VCS-Branch: master Date: Tue, 14 Feb 2023 03:40:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 578c1a9f-bf68-492c-8f70-315db3f5bb87 X-Archives-Hash: d45ee564022b9c8e0ddd10b77d927545 commit: e650022a1291ab98efd2af02a4c83c395e2d5fa1 Author: Kerin Millar plushkava net> AuthorDate: Tue Feb 14 00:29:41 2023 +0000 Commit: Sam James gentoo org> CommitDate: Tue Feb 14 03:39:49 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=e650022a Validate the exit status given to veend() and vewend() as an argument Presently, both functions trust that the first argument is either empty or a valid exit status code. If given a bogus value, the call to return may cause sh(1) to unceremoniously exit, as demonstrated below. $ dash -c 'return junk; echo done' dash: 1: return: Illegal number: junk Instead, validate that the argument is an integer whose value is greater than or equal to 0. Should validation fail, a diagnostic mesage will be printed to STDERR and the return value will be 0, provided that the call to print succeeded. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> functions.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index a5d6502..28764d8 100644 --- a/functions.sh +++ b/functions.sh @@ -346,8 +346,10 @@ veend() { if yesno "${EINFO_VERBOSE}"; then eend "$@" + elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then + printf 'Invalid argument given to veend (the exit status code must be an integer >= 0)\n' >&2 else - return "${1:-0}" + return "$1" fi } @@ -355,8 +357,10 @@ vewend() { if yesno "${EINFO_VERBOSE}"; then ewend "$@" + elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then + printf 'Invalid argument given to vewend (the exit status code must be an integer >= 0)\n' >&2 else - return "${1:-0}" + return "$1" fi }