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 E2142158010 for ; Thu, 9 Feb 2023 03:54:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 176DEE07C5; Thu, 9 Feb 2023 03:54:52 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 01C2CE07C5 for ; Thu, 9 Feb 2023 03:54:51 +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)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0D6CE340948 for ; Thu, 9 Feb 2023 03:54:51 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A18D68A6 for ; Thu, 9 Feb 2023 03:54:49 +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: <1675912464.1c1a37045e0e1b5719874a89520899f86f03dac0.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: 1c1a37045e0e1b5719874a89520899f86f03dac0 X-VCS-Branch: master Date: Thu, 9 Feb 2023 03:54:49 +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: 755e1c91-43b6-4154-9e96-499547c55b0e X-Archives-Hash: d66f3dfc8f55c575f5c1c37d25586699 commit: 1c1a37045e0e1b5719874a89520899f86f03dac0 Author: Kerin Millar plushkava net> AuthorDate: Thu Feb 9 03:02:35 2023 +0000 Commit: Sam James gentoo org> CommitDate: Thu Feb 9 03:14:24 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=1c1a3704 Don't unconditionally shift 2 in esyslog() Where esyslog() decides that it is appropriate to log a message, it unconditionally tries to shift two of of the positional parameters, regardless of how many were given. As has been seen before, this will cause a non-interactive instance of sh(1) to immediately exit. The other functions that call into it are not able to trigger this bug. Still, it's possible for esyslog() to be directly invoked with too few arguments. Fix it by testing whether a minimum of two arguments were given. Should the test fail, print an error message and return 1. Also, improve the method by which superfluous messages are ignored. The prior strategy was to join the messages by the first character of IFS, then check that the length of the resulting string is greater than 0. Instead, check that the resulting string contains at least one visible character. Finally, mention that the invocation of logger(1) is not portable. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> functions.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/functions.sh b/functions.sh index 5b1b9bf..f756a9f 100644 --- a/functions.sh +++ b/functions.sh @@ -68,20 +68,23 @@ yesno() # esyslog() { - local pri= - local tag= - - if [ -n "${EINFO_LOG}" ] && hash logger 2>/dev/null; then - pri="$1" - tag="$2" + local pri tag msg + if [ "$#" -lt 2 ]; then + printf 'Too few arguments for esyslog (got %d, expected at least 2)\n' "$#" >&2 + return 1 + elif [ -n "${EINFO_LOG}" ] && hash logger 2>/dev/null; then + pri=$1 + tag=$2 shift 2 - [ -z "$*" ] && return 0 - - logger -p "${pri}" -t "${tag}" -- "$*" + msg=$* + case ${msg} in + *[[:graph:]]*) + # This is not strictly portable because POSIX + # defines no options whatsoever for logger(1). + logger -p "${pri}" -t "${tag}" -- "${msg}" + esac fi - - return 0 } #