unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
@ 2009-05-06 14:20 Leo
  2011-02-24  2:08 ` Glenn Morris
  0 siblings, 1 reply; 8+ messages in thread
From: Leo @ 2009-05-06 14:20 UTC (permalink / raw)
  To: emacs-pretest-bug

Hi there,

The dired-x manual gives an example in using local variables for dired
buffers. However, the variable dired-actual-switches has not been marked
as safe local variable. I think this is an oversight.

,----[ (info "(dired-x)Local Variables") ]
| For example, if the user puts
| 
|      Local Variables:
|      dired-actual-switches: "-lat"
|      dired-omit-mode: t
|      End:
`----

Best wishes,

Leo






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2009-05-06 14:20 bug#3230: 23.0.93; Make dired-actual-switches safe local variable? Leo
@ 2011-02-24  2:08 ` Glenn Morris
  2011-02-24  4:46   ` Leo
  0 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2011-02-24  2:08 UTC (permalink / raw)
  To: Leo; +Cc: 3230

retitle 3230 dired-actual-switches is risky
stop

Leo wrote:

> The dired-x manual gives an example in using local variables for dired
> buffers. However, the variable dired-actual-switches has not been marked
> as safe local variable. I think this is an oversight.

As it stands, it emphatically should NOT be marked safe. Example:

cat <<EOF >| .dired
Local Variables:
dired-actual-switches: "-l ; touch /tmp/OHDEAR"
End:
EOF

rm -f /tmp/OHDEAR

emacs -Q -l dired-x
M-x dired /path/to/dir/*.el     ; wildcard is important
answer "y" to question about possibly unsafe local variable

ls /tmp/OHDEAR

Oh dear, arbitrary shell command executed with permissions of the user
running Emacs.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2011-02-24  2:08 ` Glenn Morris
@ 2011-02-24  4:46   ` Leo
  2011-02-24  6:51     ` Leo
  0 siblings, 1 reply; 8+ messages in thread
From: Leo @ 2011-02-24  4:46 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 3230

On 2011-02-24 10:08 +0800, Glenn Morris wrote:
> As it stands, it emphatically should NOT be marked safe. Example:
[...]
>
> Oh dear, arbitrary shell command executed with permissions of the user
> running Emacs.

Looks like a bug in the way dired-actual-switches is used. Should we
devise a function to check every switch in dired-actual-switches is
actual a switch?

(defun dired-actual-switches-p (switches)
  (assert (stringp switches))
  (mapc
   (lambda (switch)
     (assert (eq (aref switch 0) ?-)))
   (split-string switches nil t)))

(put 'dired-actual-switches 'safe-local-variable 'dired-actual-switches-p)

Leo





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2011-02-24  4:46   ` Leo
@ 2011-02-24  6:51     ` Leo
  2011-02-24 14:57       ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Leo @ 2011-02-24  6:51 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 3230

On 2011-02-24 12:46 +0800, Leo wrote:
> (defun dired-actual-switches-p (switches)
>   (assert (stringp switches))
>   (mapc
>    (lambda (switch)
>      (assert (eq (aref switch 0) ?-)))
>    (split-string switches nil t)))

Sorry, it should not err. I originally named the function
dired-check-switches, then changed it to be a predicate in the last
minute.

(defun dired-actual-switches-p (switches)
  (and (stringp switches)
       (catch 'exit
         (mapc (lambda (switch)
                 (unless (eq (aref switch 0) ?-)
                   (throw 'exit nil)))
               (split-string switches nil t))
         t)))

Leo





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2011-02-24  6:51     ` Leo
@ 2011-02-24 14:57       ` Stefan Monnier
  2011-02-25 14:38         ` Leo
  2011-03-01  3:25         ` Glenn Morris
  0 siblings, 2 replies; 8+ messages in thread
From: Stefan Monnier @ 2011-02-24 14:57 UTC (permalink / raw)
  To: Leo; +Cc: 3230

> (defun dired-actual-switches-p (switches)
>   (and (stringp switches)
>        (catch 'exit
>          (mapc (lambda (switch)
>                  (unless (eq (aref switch 0) ?-)
>                    (throw 'exit nil)))
>                (split-string switches nil t))
>          t)))

Hmm, what about "-l;reboot" ?
BTW, writing a predicate is the right thing to so, and the predicate
should then go to safe-local-variable.  I'd recommend something simple
like

  (defun dired-safe-switches-p (switches)
    (string-match "\\`[- [[:alnum:]]]+\\'" switches))

Hopefully that one is safe (tho maybe we should check string-length to
avoid attacks playing on overflow).  And if it proves too restrictive,
we can make it a bit more permissive once we encounter a particular
example that warrants it.
    

        Stefan





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2011-02-24 14:57       ` Stefan Monnier
@ 2011-02-25 14:38         ` Leo
  2011-03-01  3:25         ` Glenn Morris
  1 sibling, 0 replies; 8+ messages in thread
From: Leo @ 2011-02-25 14:38 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 3230

On 2011-02-24 22:57 +0800, Stefan Monnier wrote:
> Hmm, what about "-l;reboot" ?

Thanks.

> BTW, writing a predicate is the right thing to so, and the predicate
> should then go to safe-local-variable.  I'd recommend something simple
> like
>
>   (defun dired-safe-switches-p (switches)
>     (string-match "\\`[- [[:alnum:]]]+\\'" switches))

A typo: should be [:alnum:].

> Hopefully that one is safe (tho maybe we should check string-length to
> avoid attacks playing on overflow).  And if it proves too restrictive,
> we can make it a bit more permissive once we encounter a particular
> example that warrants it.
>
>         Stefan

I think I like this. Glenn, would you agree to this?

If this is accepted, I have one use case that can be easily done:

I have one directory where I file regularly. I like that directory to be
sorted by time instead of by name in dired. This change will allow me to
set dired-actual-switches to achieve that.

Leo





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2011-02-24 14:57       ` Stefan Monnier
  2011-02-25 14:38         ` Leo
@ 2011-03-01  3:25         ` Glenn Morris
  2011-03-01  4:31           ` Juanma Barranquero
  1 sibling, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2011-03-01  3:25 UTC (permalink / raw)
  To: 3230-done

Version: 24.1

Stefan Monnier wrote:

> should then go to safe-local-variable.  I'd recommend something simple
> like
>
>   (defun dired-safe-switches-p (switches)
>     (string-match "\\`[- [[:alnum:]]]+\\'" switches))

Added.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#3230: 23.0.93; Make dired-actual-switches safe local variable?
  2011-03-01  3:25         ` Glenn Morris
@ 2011-03-01  4:31           ` Juanma Barranquero
  0 siblings, 0 replies; 8+ messages in thread
From: Juanma Barranquero @ 2011-03-01  4:31 UTC (permalink / raw)
  To: 3230, rgm; +Cc: 3230-done

On Tue, Mar 1, 2011 at 04:25, Glenn Morris <rgm@gnu.org> wrote:

>>   (defun dired-safe-switches-p (switches)
>>     (string-match "\\`[- [[:alnum:]]]+\\'" switches))

This is a poster case for using `string-match-p'.

    Juanma





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-01  4:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-06 14:20 bug#3230: 23.0.93; Make dired-actual-switches safe local variable? Leo
2011-02-24  2:08 ` Glenn Morris
2011-02-24  4:46   ` Leo
2011-02-24  6:51     ` Leo
2011-02-24 14:57       ` Stefan Monnier
2011-02-25 14:38         ` Leo
2011-03-01  3:25         ` Glenn Morris
2011-03-01  4:31           ` Juanma Barranquero

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).