Package: sensible-utils
Version: 0.0.22
Severity: normal

After the upgrade to 0.0.22, I'm getting the following error with
sensible-pager:

realpath: '': No such file or directory

(the other sensible-* utilities are likely to have the same issue
since the related code is very similar).

This is due to

    # Prevent recursive loops, where environment variables are set to this 
script
    [ x$(realpath "$(command -v "$candidate" || true)" || true) = x"$program" ] 
&& return

where $candidate is a command with arguments. For instance,
I have PAGER="less -Lis". Hence the issue.

The full string for "command -v" is expected to be the executable name
(without arguments). So the executable is not found, and "command -v"
fails without any output, so that realpath outputs an error to stderr
for this reason.

There is the same issue when the command doesn't exist:

cventin:~> PAGER=foo sensible-pager
realpath: '': No such file or directory
PAGER: 1: foo: not found
Missing filename ("less --help" for help)

In any case, the "realpath: '': No such file or directory" just
concerns internals and should be hidden from the user.

The problem is actually worse than the error message as there can
be a loop:

cventin:~> PAGER="sensible-pager " sensible-pager
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
[...]

So I suggest 2 fixes:

1. In the candidate, take only everything until the first space,
   i.e. use "${candidate%% *}" instead of "$candidate".

2. Redirect the realpath standard error to /dev/null in order to
   avoid the error message when the executable is not found.

This gives:

    # Prevent recursive loops, where environment variables are set to this 
script
    [ x$(realpath "$(command -v "${candidate%% *}" || true)" 2> /dev/null || 
true) = x"$program" ] && return

-- System Information:
Debian Release: trixie/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'stable-updates'), (500, 
'stable-security'), (500, 'stable-debug'), (500, 'proposed-updates-debug'), 
(500, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.6.13-amd64 (SMP w/12 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- no debconf information

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to