[PATCH] show/ls: handle pass file with empty basename

Doan Tran Cong Danh congdanhqx at gmail.com
Thu Nov 21 14:20:29 CET 2019


We're handling both show/ls with cmd_show, with a default to show
password if the password file exists and list if not.

In case of user have a .gpg file in the top level directory,
we will show that password because "$PREFIX/.gpg" exists.

It's surprising to some users, since our manual clearly states that
pass-show needs required argument.

Correct it by adding a check for number of arguments.

If users really want to show that password, they should explicitly ask
by:
    pass ""

Signed-off-by: Doan Tran Cong Danh <congdanhqx at gmail.com>
---
 src/password-store.sh     | 2 +-
 tests/t0020-show-tests.sh | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 1d119f2..c1ea2fd 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -379,7 +379,7 @@ cmd_show() {
 	local path="$1"
 	local passfile="$PREFIX/$path.gpg"
 	check_sneaky_paths "$path"
-	if [[ -f $passfile ]]; then
+	if [[ $# != 0 && -f $passfile ]]; then
 		if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
 			pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | $BASE64)" || exit $?
 			echo "$pass" | $BASE64 -d
diff --git a/tests/t0020-show-tests.sh b/tests/t0020-show-tests.sh
index a4b782f..3836ed2 100755
--- a/tests/t0020-show-tests.sh
+++ b/tests/t0020-show-tests.sh
@@ -15,6 +15,13 @@ test_expect_success 'Test "show" command with spaces' '
 	[[ $("$PASS" show "I am a cred with lots of spaces") == "BLAH!!" ]]
 '
 
+test_expect_success 'Test "show/ls" command with empty name' '
+	"$PASS" insert -e ""<<<"BLAH!!!" &&
+	[[ $("$PASS" "") == "BLAH!!!" ]] &&
+	[[ $("$PASS" | wc -l) == 3 ]]
+'
+
+
 test_expect_success 'Test "show" of nonexistant password' '
 	test_must_fail "$PASS" show cred2
 '
-- 
2.24.0.158.gd77a74f4dd.dirty



More information about the Password-Store mailing list