From: Stefan Berger <stefanb@linux.ibm.com>
To: linux-integrity@vger.kernel.org
Cc: zohar@linux.ibm.com, Stefan Berger <stefanb@linux.ibm.com>
Subject: [ima-evm-utils PATCH v2 04/14] tests: Address issues raised by shellcheck SC2320
Date: Tue, 28 Nov 2023 13:16:02 -0500 [thread overview]
Message-ID: <20231128181613.1159958-5-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20231128181613.1159958-1-stefanb@linux.ibm.com>
Address issues raised by shellcheck SC2320:
"This $? refers to echo/printf, not a previous command.
Assign to variable to avoid it being overwritten."
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
tests/Makefile.am | 2 +-
tests/mmap_check.test | 8 +++-----
tests/portable_signatures.test | 9 +++------
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6fe18e4..3713771 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,7 +26,7 @@ clean-local:
distclean: distclean-keys
shellcheck:
- shellcheck -i SC2086,SC2181,SC2046 \
+ shellcheck -i SC2086,SC2181,SC2046,SC2320 \
functions.sh gen-keys.sh install-fsverity.sh \
install-mount-idmapped.sh install-openssl3.sh \
install-swtpm.sh install-tss.sh softhsm_setup \
diff --git a/tests/mmap_check.test b/tests/mmap_check.test
index 2dd3433..e3e5c71 100755
--- a/tests/mmap_check.test
+++ b/tests/mmap_check.test
@@ -97,14 +97,12 @@ check_load_ima_rule() {
new_policy=$(mktemp -p "$g_mountpoint")
echo "$1" > "$new_policy"
- echo "$new_policy" > /sys/kernel/security/ima/policy
- result=$?
- rm -f "$new_policy"
-
- if [ "$result" -ne 0 ]; then
+ if ! echo "$new_policy" > /sys/kernel/security/ima/policy; then
+ rm -f "$new_policy"
echo "${RED}Failed to set IMA policy${NORM}"
return "$HARDFAIL"
fi
+ rm -f "$new_policy"
return "$OK"
}
diff --git a/tests/portable_signatures.test b/tests/portable_signatures.test
index 9f3339b..7ddd149 100755
--- a/tests/portable_signatures.test
+++ b/tests/portable_signatures.test
@@ -80,7 +80,6 @@ METADATA_CHANGE_FOWNER_2=3002
check_load_ima_rule() {
local rule_loaded
- local result
local new_policy
rule_loaded=$(grep "$1" /sys/kernel/security/ima/policy)
@@ -88,14 +87,12 @@ check_load_ima_rule() {
new_policy=$(mktemp -p "$g_mountpoint")
echo "$1" > "$new_policy"
evmctl sign -o -a sha256 --imasig --key "$key_path" "$new_policy" &> /dev/null
- echo "$new_policy" > /sys/kernel/security/ima/policy
- result=$?
- rm -f "$new_policy"
-
- if [ "$result" -ne 0 ]; then
+ if ! echo "$new_policy" > /sys/kernel/security/ima/policy; then
+ rm -f "$new_policy"
echo "${RED}Failed to set IMA policy${NORM}"
return "$FAIL"
fi
+ rm -f "${new_policy}"
fi
return "$OK"
--
2.43.0
next prev parent reply other threads:[~2023-11-28 18:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 18:15 [ima-evm-utils PATCH v2 00/14] Enable shellcheck and fix some issues Stefan Berger
2023-11-28 18:15 ` [ima-evm-utils PATCH v2 01/14] tests: Address issues raised by shellcheck SC2086 & enable shellcheck Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 02/14] tests: Address issues raised by shellcheck SC2181 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 03/14] tests: Address issues raised by shellcheck SC2046 Stefan Berger
2023-11-28 18:16 ` Stefan Berger [this message]
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 05/14] tests: Address issues raised by shellcheck SC2317 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 06/14] tests: Address issues raised by shellcheck SC2034 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 07/14] tests: Address issues raised by shellcheck SC2164 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 08/14] tests: Address issues raised by shellcheck SC2166 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 09/14] tests: Address issues raised by shellcheck SC2294 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 10/14] tests: Address issues raised by shellcheck SC2206 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 11/14] tests: Address issues raised by shellcheck SC2196 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 12/14] tests: Address issues raised by shellcheck SC2043 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 13/14] tests: Address issues raised by shellcheck SC2295 Stefan Berger
2023-11-28 18:16 ` [ima-evm-utils PATCH v2 14/14] tests: Address issues raised by shellcheck SC2003 Stefan Berger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231128181613.1159958-5-stefanb@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=linux-integrity@vger.kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox