[pass] Fix mktemp template to work with GNU Coreutils

Deny Dias deny at macpress.com.br
Wed Feb 18 18:50:38 CET 2015


GNU Coreutils (e.g. coreutils-8.23) imposes a limit of exactly six (6) X's to
define a valid template. If this limit is not observed when passing arguments to
mktemp, it throws an error:

 mktemp: cannot create temp file /dev/shm/pass.XXXXXXXD2gHRw/XXXXX: \
  Invalid argument

This error makes password-store.sh to fail when someone run edit command in
systems relying to GNU Coreutils (e.g. Slackware).

This is what 'man mktemp' says about the template size in such systems:

 ...The template may be any filename with six (6) `Xs' appended to it, for
 example /tmp/tfile.XXXXXX.  If no template is specified a default of tmp.XXXXXX
 is  used  and  the  -t  flag  is implied (see below)...

The patch for the fix is bellow.

Best regards,

Deny Dias.

--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -157,7 +157,7 @@ tmpdir() {
        [[ -n $SECURE_TMPDIR ]] && return
        local warn=1
        [[ $1 == "nowarn" ]] && warn=0
-       local template="$PROGRAM.XXXXXXXXXXXXX"
+       local template="$PROGRAM.XXXXXX"
        if [[ -d /dev/shm && -w /dev/shm && -x /dev/shm ]]; then
                SECURE_TMPDIR="$(mktemp -d "/dev/shm/$template")"
                remove_tmpfile() {
@@ -411,7 +411,7 @@ cmd_edit() {
        local passfile="$PREFIX/$path.gpg"

        tmpdir #Defines $SECURE_TMPDIR
-       local tmp_file="$(mktemp -u "$SECURE_TMPDIR/XXXXX")-${path//\//-}.txt"
+       local tmp_file="$(mktemp -u "$SECURE_TMPDIR/XXXXXX")-${path//\//-}.txt"

        local action="Add"

More information about the Password-Store mailing list