[PATCH] emacs: fix infloop in password-store--run

Kai Tetzlaff pwstore at tetzco.de
Sun Feb 27 09:02:47 UTC 2022


Actually, checking the elisp reference manual provided some more
insight:

       If a connection from a process contains buffered data,
    ‘accept-process-output’ can return non-‘nil’ even after the process has
    exited.  Therefore, although the following loop:
    
         ;; This loop contains a bug.
         (while (process-live-p process)
           (accept-process-output process))
    
    will often read all output from PROCESS, it has a race condition and can
    miss some output if ‘process-live-p’ returns ‘nil’ while the connection
    still contains data.  Better is to write the loop like this:
    
         (while (accept-process-output process))

So instead of:

>   (let ((output nil)
>         (slept-for 0)
>         (process (apply #'password-store--run-1
>                         (lambda (password)
>                           (setq output password))
>                         (delq nil args))))
>     (accept-process-output process .1 nil t)
>     (while (process-live-p process)
>       (accept-process-output process .1 nil t))
>     output))

it should probably better be:

  (let ((output nil)
        (slept-for 0)
        (process (apply #'password-store--run-1
                        (lambda (password)
                          (setq output password))
                        (delq nil args))))
    ;; wait for output or process termination (max. wait time: 5s)
    (while (accept-process-output process 5.0))
    output))


I added a timeout which terminates `accept-process-output' after 5s just
to make sure that a non-responsive pass process doesn't block emacs.
It's debatable if this is needed or even makes any sense.

An updated patch is attached.

Best Regards,
Kai

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-infloop-in-password-store-run.patch
Type: text/x-diff
Size: 1801 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20220227/cd8e1f7b/attachment.bin>


More information about the Password-Store mailing list