GNU bug report logs - #23959
rgrep fails due to unescaped shell meta character

Previous Next

Package: emacs;

Reported by: Ethan Glasser-Camp <ethan.glasser.camp <at> gmail.com>

Date: Tue, 12 Jul 2016 19:29:01 UTC

Severity: normal

Found in version 25.0.94

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23959 in the body.
You can then email your comments to 23959 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Tue, 12 Jul 2016 19:29:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ethan Glasser-Camp <ethan.glasser.camp <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 12 Jul 2016 19:29:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ethan Glasser-Camp <ethan.glasser.camp <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.94; find: missing argument to `-exec'
Date: Tue, 12 Jul 2016 15:27:39 -0400
1. Install fish-shell (http://fishshell.com/) and use it as your default
shell, although it may be enough to launch emacs from inside fish.

2. emacs -Q

3. M-x rgrep RET

4. any string RET

5. any directory RET

Expected result:

grep is invoked on the given directory and files are returned.

Actual result:

find: missing argument to `-exec'

I believe this is because the fish shell interprets the "{}" as a brace
expansion -- see
http://fishshell.com/docs/current/index.html#expand-brace -- and needs
the braces to be escaped. Editing the grep command using C-u and
inserting quotes around the braces makes it work as expected.



In GNU Emacs 25.0.94.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.20.4)
 of 2016-05-18 built on buildhw-10.phx2.fedoraproject.org
Windowing system distributor 'Fedora Project', version 11.0.11803000
System Description:	Fedora release 24 (Twenty Four)

Configured using:
 'configure --build=x86_64-redhat-linux-gnu
 --host=x86_64-redhat-linux-gnu --program-prefix=
 --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
 --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
 --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
 --libexecdir=/usr/libexec --localstatedir=/var
 --sharedstatedir=/var/lib --mandir=/usr/share/man
 --infodir=/usr/share/info --with-dbus --with-gif --with-jpeg --with-png
 --with-rsvg --with-tiff --with-xft --with-xpm --with-x-toolkit=gtk3
 --with-gpm=no --with-xwidgets build_alias=x86_64-redhat-linux-gnu
 host_alias=x86_64-redhat-linux-gnu 'CFLAGS=-DMAIL_USE_LOCKF -O2 -g
 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
 -m64 -mtune=generic' LDFLAGS=-Wl,-z,relro
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GCONF GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XWIDGETS

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/git-init.el (source)...done
Loading /usr/share/emacs/site-lisp/site-start.d/mercurial-site-start.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
You can run the command ‘set-variable’ with M-x s-va RET
Loading sendmail...done
user-error: Value ‘(quote header)’ does not match type choice of mail-envelope-from
M-p is undefined
You can run the command ‘set-variable’ with M-x s-va RET
Grep exited abnormally with code 1

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message idna format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader find-dired
dired grep compile comint ansi-color ring sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils cus-edit cus-start cus-load
wid-edit thingatpt help-fns help-mode easymenu cl-loaddefs pcase cl-lib
time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel x-win term/common-win x-dnd tool-bar dnd fontset
image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cl-generic cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote dbusbind inotify dynamic-setting
system-font-setting font-render-setting xwidget-internal move-toolbar
gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 114420 7060)
 (symbols 48 21837 0)
 (miscs 40 94 116)
 (strings 32 19996 4525)
 (string-bytes 1 562787)
 (vectors 16 13396)
 (vector-slots 8 444288 4260)
 (floats 8 179 7)
 (intervals 56 325 0)
 (buffers 976 13)
 (heap 1024 22685 1616))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Wed, 13 Jul 2016 04:46:02 GMT) Full text and rfc822 format available.

Message #8 received at 23959 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 23959 <at> debbugs.gnu.org
Subject: 25.0.94; find: missing argument to `-exec'
Date: Wed, 13 Jul 2016 13:45:15 +0900 (JST)
Thank you for the report.
>I believe this is because the fish shell interprets the "{}" as a brace
>expansion -- see
>http://fishshell.com/docs/current/index.html#expand-brace -- and needs
>the braces to be escaped. Editing the grep command using C-u and
>inserting quotes around the braces makes it work as expected.
Yes, braces should be escaped in commands to be processed by a shell.
I am going to apply following patch to the master branch:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 2b44b58..f7f097b 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -543,7 +543,9 @@ grep-compute-defaults
   (let* ((host-id
 	  (intern (or (file-remote-p default-directory) "localhost")))
 	 (host-defaults (assq host-id grep-host-defaults-alist))
-	 (defaults (assq nil grep-host-defaults-alist)))
+	 (defaults (assq nil grep-host-defaults-alist))
+         (quot-braces (shell-quote-argument "{}"))
+         (quot-scolon (shell-quote-argument ";")))
     ;; There are different defaults on different hosts.  They must be
     ;; computed for every host once.
     (dolist (setting '(grep-command grep-template
@@ -637,9 +639,8 @@ grep-compute-defaults
 				     "")))
 			 (cons
 			  (if (eq grep-find-use-xargs 'exec-plus)
-			      (format "%s %s{} +" cmd0 null)
-			    (format "%s {} %s%s" cmd0 null
-				    (shell-quote-argument ";")))
+			      (format "%s %s%s +" cmd0 null quot-braces)
+			    (format "%s %s %s%s" cmd0 quot-braces null 
quot-scolon))
 			  (1+ (length cmd0)))))
 		      (t
 		       (format "%s . -type f -print | \"%s\" %s"
@@ -655,12 +656,11 @@ grep-compute-defaults
 			 (format "%s <D> <X> -type f <F> -print0 | \"%s\" 
-0 %s"
 				 find-program xargs-program gcmd))
 			((eq grep-find-use-xargs 'exec)
-			 (format "%s <D> <X> -type f <F> -exec %s {} %s%s"
-				 find-program gcmd null
-				 (shell-quote-argument ";")))
+			 (format "%s <D> <X> -type f <F> -exec %s %s %s%s"
+				 find-program gcmd quot-braces null 
quot-scolon))
 			((eq grep-find-use-xargs 'exec-plus)
-			 (format "%s <D> <X> -type f <F> -exec %s %s{} +"
-				 find-program gcmd null))
+			 (format "%s <D> <X> -type f <F> -exec %s %s%s +"
+				 find-program gcmd null quot-braces))
 			(t
 			 (format "%s <D> <X> -type f <F> -print | \"%s\" 
%s"
 				 find-program xargs-program gcmd))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.20.6)
 of 2016-07-13
Repository revision: 54b7eb0dee2397f1430e81b7356f8efb19946ba0





Changed bug title to 'rgrep fails due to unescaped shell meta character' from '25.0.94; find: missing argument to `-exec'' Request was from Tino Calancha <tino.calancha <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 13 Jul 2016 04:52:02 GMT) Full text and rfc822 format available.

Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Wed, 13 Jul 2016 04:54:02 GMT) Full text and rfc822 format available.

Notification sent to Ethan Glasser-Camp <ethan.glasser.camp <at> gmail.com>:
bug acknowledged by developer. (Wed, 13 Jul 2016 04:54:02 GMT) Full text and rfc822 format available.

Message #15 received at 23959-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 23959-done <at> debbugs.gnu.org
Date: Wed, 13 Jul 2016 13:53:44 +0900 (JST)
Fixed in master branch




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Wed, 13 Jul 2016 14:46:01 GMT) Full text and rfc822 format available.

Message #18 received at 23959 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 23959 <at> debbugs.gnu.org
Subject: Re: bug#23959: 25.0.94; find: missing argument to `-exec'
Date: Wed, 13 Jul 2016 17:45:00 +0300
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Date: Wed, 13 Jul 2016 13:45:15 +0900 (JST)
> 
> Thank you for the report.
> >I believe this is because the fish shell interprets the "{}" as a brace
> >expansion -- see
> >http://fishshell.com/docs/current/index.html#expand-brace -- and needs
> >the braces to be escaped. Editing the grep command using C-u and
> >inserting quotes around the braces makes it work as expected.
> Yes, braces should be escaped in commands to be processed by a shell.
> I am going to apply following patch to the master branch:
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
> index 2b44b58..f7f097b 100644
> --- a/lisp/progmodes/grep.el
> +++ b/lisp/progmodes/grep.el
> @@ -543,7 +543,9 @@ grep-compute-defaults
>     (let* ((host-id
>   	  (intern (or (file-remote-p default-directory) "localhost")))
>   	 (host-defaults (assq host-id grep-host-defaults-alist))
> -	 (defaults (assq nil grep-host-defaults-alist)))
> +	 (defaults (assq nil grep-host-defaults-alist))
> +         (quot-braces (shell-quote-argument "{}"))
> +         (quot-scolon (shell-quote-argument ";")))

But shell-quote-argument is not documented to support fish shell, is
it?  I think the problem is that the OP somehow sets up that shell as
the one used by Emacs when invoking shell commands, which is not a
recommended practice.

> -			      (format "%s %s{} +" cmd0 null)
> -			    (format "%s {} %s%s" cmd0 null
> -				    (shell-quote-argument ";")))
> +			      (format "%s %s%s +" cmd0 null quot-braces)
> +			    (format "%s %s %s%s" cmd0 quot-braces null 

I'm not sure we can assume a quoted argument can be safely
concatenated to an unquoted one.  (Yes, I know the original code used
that for the semi-colon.)

I can't say I'm happy with this solution, sorry.  But thanks for
working on this problem.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Wed, 13 Jul 2016 14:47:02 GMT) Full text and rfc822 format available.

Message #21 received at 23959 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 23959 <at> debbugs.gnu.org, ethan.glasser.camp <at> gmail.com
Subject: Re: bug#23959: (no subject)
Date: Wed, 13 Jul 2016 17:46:07 +0300
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Date: Wed, 13 Jul 2016 13:53:44 +0900 (JST)
> 
> Fixed in master branch

That was premature, please leave some time for people to respond to
the proposed solution.  Especially when the issue involves
portability.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Wed, 13 Jul 2016 14:53:01 GMT) Full text and rfc822 format available.

Message #24 received at 23959 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 23959 <at> debbugs.gnu.org, ethan.glasser.camp <at> gmail.com,
 Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#23959: (no subject)
Date: Wed, 13 Jul 2016 23:52:47 +0900 (JST)

On Wed, 13 Jul 2016, Eli Zaretskii wrote:

> That was premature, please leave some time for people to respond to
> the proposed solution.  Especially when the issue involves
> portability.

Sure.  Sorry for my impetus Eli.
Please, don't hesitate to let me now if you want i revert this commit.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Wed, 13 Jul 2016 15:16:02 GMT) Full text and rfc822 format available.

Message #27 received at 23959 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 23959 <at> debbugs.gnu.org, ethan.glasser.camp <at> gmail.com,
 tino.calancha <at> gmail.com
Subject: Re: bug#23959: (no subject)
Date: Wed, 13 Jul 2016 18:15:23 +0300
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Date: Wed, 13 Jul 2016 23:52:47 +0900 (JST)
> cc: Tino Calancha <tino.calancha <at> gmail.com>, 23959 <at> debbugs.gnu.org, 
>     ethan.glasser.camp <at> gmail.com
> 
> On Wed, 13 Jul 2016, Eli Zaretskii wrote:
> 
> > That was premature, please leave some time for people to respond to
> > the proposed solution.  Especially when the issue involves
> > portability.
> 
> Sure.  Sorry for my impetus Eli.
> Please, don't hesitate to let me now if you want i revert this commit.

Let's hear what others think about this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23959; Package emacs. (Wed, 13 Jul 2016 15:56:01 GMT) Full text and rfc822 format available.

Message #30 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit--Claudel <clement.pit <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#23959: (no subject)
Date: Wed, 13 Jul 2016 17:55:23 +0200
[Message part 1 (text/plain, inline)]
On 2016-07-13 17:15, Eli Zaretskii wrote:
>> From: Tino Calancha <tino.calancha <at> gmail.com>
>> Date: Wed, 13 Jul 2016 23:52:47 +0900 (JST)
>> cc: Tino Calancha <tino.calancha <at> gmail.com>, 23959 <at> debbugs.gnu.org, 
>>     ethan.glasser.camp <at> gmail.com
>>
>> On Wed, 13 Jul 2016, Eli Zaretskii wrote:
>>
>>> That was premature, please leave some time for people to respond to
>>> the proposed solution.  Especially when the issue involves
>>> portability.
>>
>> Sure.  Sorry for my impetus Eli.
>> Please, don't hesitate to let me now if you want i revert this commit.
> 
> Let's hear what others think about this.

Is there any reason why mapconcat + shell-quote-arguments doesn't work here?

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 11 Aug 2016 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 315 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.