[PATCH] Fix handling of SIGPIPE in 'pass show --clip'

Craig B. Agricola craig at theagricolas.org
Tue Apr 12 23:56:22 UTC 2022


When 'pass show' is used with the '--clip' option (or '--qrcode'), the
decrypted password file is piped to tail and then head to extract just the
first line.  If the password entry file is long enough, then the pipe is closed
before the whole GPG output pipe has been consumed, leading to a SIGPIPE.
This SIGPIPE causes the code to exit with a return value of 141 (128 plus the
numerical signal number for SIGPIPE).  It is appropriate to exit, passing out
the return value from the pipe, in case there is an actual problem.

That said, because it is intentional that the pipe is being abandoned when head
gets what it needs, the appropriate fix seems to be to turn off the 'pipefail'
shell option, just for this particular pipeline.
---
 src/password-store.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..cb11dfb 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -388,7 +388,7 @@ cmd_show() {
 			echo "$pass" | $BASE64 -d
 		else
 			[[ $selected_line =~ ^[0-9]+$ ]] || die "Clip location '$selected_line' is not a number."
-			pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +${selected_line} | head -n 1)" || exit $?
+			pass="$(set +o pipefail; $GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +${selected_line} | head -n 1)" || exit $?
 			[[ -n $pass ]] || die "There is no password to put on the clipboard at line ${selected_line}."
 			if [[ $clip -eq 1 ]]; then
 				clip "$pass" "$path"
-- 
2.27.0


More information about the Password-Store mailing list