GNU bug report logs - #71935
split-string-and-unquote mishandles dired-listing-switches with '

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Thu, 4 Jul 2024 07:02:01 UTC

Severity: normal

Fixed in version 30.0.60

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 71935 <at> debbugs.gnu.org
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
Date: Thu, 04 Jul 2024 20:56:11 +0300
> From: Juri Linkov <juri <at> linkov.net>
> Cc: 71935 <at> debbugs.gnu.org
> Date: Thu, 04 Jul 2024 19:10:17 +0300
> 
> >> 1. (setopt dired-listing-switches "-al --block-size='1")
> >> 2. C-x d /tmp/*
> >>
> >>   /tmp:
> >>   wildcard *
> >>   /bin/bash: -c: line 0: unexpected EOF while looking for matching `''
> >>   /bin/bash: -c: line 1: syntax error: unexpected end of file
> >>
> >> 3. (setopt dired-listing-switches "-al --block-size=\\'1")
> >> 4. C-x d /tmp/
> >>
> >> Debugger entered--Lisp error: (error "Listing directory failed but ‘access-file’ worked")
> >>   error("Listing directory failed but `access-file' worked")
> >>   insert-directory("/tmp/" "--dired -N -al --block-size=\\'1" nil t)
> >
> > I think the part of insert-directory that deals with wildcard lacks
> > the call to shell-quote-argument here:
> >
> > 		      ;; NB since switches is passed to the shell, be
> > 		      ;; careful of malicious values, eg "-l;reboot".
> > 		      ;; See eg dired-safe-switches-p.
> > 		      (call-process
> > 		       shell-file-name nil t nil
> > 		       shell-command-switch
> > 		       (concat (if (memq system-type '(ms-dos windows-nt))
> > 				   ""
> > 				 "\\") ; Disregard Unix shell aliases!
> > 			       insert-directory-program
> > 			       " -d "
> > 			       (if (stringp switches)
> > 				   switches
> > 				 (mapconcat #'identity switches " "))
> >
> > Can you try running each switch through shell-quote-argument?
> 
> This part of insert-directory is used only in case of 1-2 above,
> i.e. for wildcard '/tmp/*'.  In this case the value of 'switches'
> is "--dired -N -al --block-size='1", and 'shell-quote-argument'
> returns "--dired\\ -N\\ -al\\ --block-size\\=\\'1" that fails.

I meant to call shell-quote-argument on each option, before they are
concatenated.

> For the non-wildcard case of 3-4 above, this doesn't help either.
> Using (mapcar 'shell-quote-argument (split-string-and-unquote switches))
> on ("--dired" "-N" "-al" "--block-size=\\'1") returns
> ("--dired" "-N" "-al" "--block-size\\=\\\\\\'1") that fails with
> 
>   /bin/ls: unrecognized option '--block-size\=\\\'1'

Why did you use "--block-size=\\'1"?  My idea is that the quoting
should not come from the user.




This bug report was last modified 320 days ago.

Previous Next


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