Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 646884 - =sys-apps/less-529 - 'v' fails to pass path that includes whitespace to $EDITOR
Summary: =sys-apps/less-529 - 'v' fails to pass path that includes whitespace to $EDITOR
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-07 10:14 UTC by Hadrien Lacour
Modified: 2018-06-26 02:51 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
top: 487 / bottom: 529 (2018-02-07_11:11:33.png,71.27 KB, image/png)
2018-02-07 10:14 UTC, Hadrien Lacour
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hadrien Lacour 2018-02-07 10:14:07 UTC
Created attachment 518342 [details]
top: 487 / bottom: 529

Hello,

when using the latest less with EDITOR="emacs -nw -q -l ~/.emacs.term" and a file with a whitespace embedded in its name, using 'v' (open file in editor) doesn't pass it cleanly to EDITOR (it's IFS splitted). Downgrading to 487 gives an appropriate behaviour.
Comment 1 Roman Žilka 2018-05-11 21:26:42 UTC
I can replicate this with v529 and v530 and VISUAL="/usr/bin/vim". In fact, less may have stopped handling all special shell chars. For instance, this makes less 529/530 execute "date" for me:
$ touch 'file;date'
$ less file\;date
   -> press 'v'

On a quick glance, the following part in "diff -u less-487/main.c less-530/main.c" looks suspicious:

--- less-487/main.c     2016-10-25 16:37:35.000000000 +0200
+++ less-530/main.c     2017-12-05 23:56:50.000000000 +0100
(...)
@@ -188,25 +190,24 @@
(...)
-               filename = shell_quote(*argv);
-               if (filename == NULL)
-                       filename = *argv;
-               argv++;
-               (void) get_ifile(filename, ifile);
+               (void) get_ifile(*argv++, ifile);
                ifile = prev_ifile(NULL_IFILE);
-               free(filename);

I wonder if reversing this change would fix the issue (no time to try now). I believe get_ifile() has the side effect of registering a string to serve as a parameter to the editor cmd later. shell_quote() may be taking care of special shell chars (incl. spaces and semicolons as DEF_METACHARS suggests) and may indeed be necessary, because in the end less runs the external editor using system().
Comment 2 Roman Žilka 2018-05-12 11:23:57 UTC
Nevermind, this hack doesn't work. But gdb confirms the general idea: a shell_quote() of the filename would solve the problem in less-530. A less-487 flow example (shell_quote() prefixes spaces with the necessary backslashes, lsystem() is a wrapper for system()):

In the segment of main() quoted in comment 1:
  shell_quote("/home/nan/del del2") -> "/home/nan/del\\ del2"
which later results in:
  lsystem("/usr/bin/vim +1 /home/nan/del\\ del2")
which in turn correctly calls:
  shell_quote("/usr/bin/vim +1 /home/nan/del\\ del2") -> "/usr/bin/vim\\ +1\\ /home/nan/del\\\\\\ del2"
  system("/bin/bash -c /usr/bin/vim\\ +1\\ /home/nan/del\\\\\\ del2")

less-530 does no shell_quote in main() (or anywhere else sufficiently early) and only does:
  lsystem("/usr/bin/vim +1 /home/nan/del del2")
which has vim edit two distinct files eventually:
  shell_quote("/usr/bin/vim +1 /home/nan/del del2") -> "/usr/bin/vim\\ +1\\ /home/nan/del\\ del2"
  system("/bin/bash -c /usr/bin/vim\\ +1\\ /home/nan/del\\ del2")

Incidentally, less-530 contains an additional call to shell_quote() in the body of lglob(), as opposed to less-487. Perhaps that was meant to take care of things in some way.

By the way, less currently does: system("bash -c <something>") which execs /bin/sh -c "bash -c <something>".

Hopefully this saves somebody a bit of debugging time.
Comment 3 Roman Žilka 2018-05-12 15:55:00 UTC
FYI: I've notified the upstream developer of this URL.
Comment 4 Roman Žilka 2018-05-14 07:07:35 UTC
Received a reply: fixed in v531, release pending.
Comment 5 Larry the Git Cow gentoo-dev 2018-05-16 09:38:40 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=cf063984cc7b2efb34e61c56a15b53362e7e277d

commit cf063984cc7b2efb34e61c56a15b53362e7e277d
Author:     Lars Wendler <polynomial-c@gentoo.org>
AuthorDate: 2018-05-16 09:36:25 +0000
Commit:     Lars Wendler <polynomial-c@gentoo.org>
CommitDate: 2018-05-16 09:38:32 +0000

    sys-apps/less: Bump to version 531
    
    Bug: https://bugs.gentoo.org/646884
    Package-Manager: Portage-2.3.36, Repoman-2.3.9

 sys-apps/less/Manifest        |  1 +
 sys-apps/less/less-531.ebuild | 44 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
Comment 6 SpanKY gentoo-dev 2018-06-26 02:51:37 UTC
i don't think there's anything left here