Subject: Re: bug#19192: 25.0.50; TRAMP uses `dired-listing-switches' for ftp-connection

From: Rasmus <[email-masked]>
Date: Wed, 10 Dec 2014 14:16:25 +0100

Michael Albinus <[email-masked]> writes:

> So far it seems to be OK, but wouldn't it be safer to disallow all
> options to ftp which start with "--"? I understand that you have checked
> it with your ftp client, but you cannot assume that everybody uses the same
> version of ftp and ls as you do. Samr for the ftp server.

As you prefer.  

This patch disallow
   (string-match "--\\w\\{2,\\}" switches)
which should be enough to capture switches starting with --, I guess.

—Rasmus

-- 
The right to be left alone is a human right
>From 55bf708060ddf05a87df4f1f22185aceac74d9c6 Mon Sep 17 00:00:00 2001
From: Rasmus <[email-masked]>
Date: Sat, 29 Nov 2014 13:12:10 +0100
Subject: [PATCH] ange-ftp.el: Disallow more dired ls-flags

* net/ange-ftp.el (ange-ftp-switches-ok): Disallow flags causing
trouble with ls over ftp.  These flags result in ls returning no
output, causing Tramp-breakage.

Fixes: debbugs:19192
---
 lisp/ChangeLog       | 6 ++++++
 lisp/net/ange-ftp.el | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 454ee00..09b64f5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-29  Rasmus Pank Roulund  <[email-masked]>
+
+	* net/ange-ftp.el (ange-ftp-switches-ok): Disallow flags causing
+	trouble with ls over ftp.  These flags result in ls returning no
+	output, causing Tramp-breakage.  (bug#19192)
+
 2014-12-10  Andreas Schwab  <[email-masked]>
 
 	* files.el (file-tree-walk): Use file-name-as-directory
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el
index d7632ed..5e9bc27 100644
--- a/lisp/net/ange-ftp.el
+++ b/lisp/net/ange-ftp.el
@@ -2831,16 +2831,20 @@ match subdirectories as well.")
 		      files ange-ftp-files-hashtable)))
 
 (defun ange-ftp-switches-ok (switches)
-  "Return SWITCHES (a string) if suitable for our use."
+  "Return SWITCHES (a string) if suitable for use with ls over ftp."
   (and (stringp switches)
        ;; We allow the A switch, which lists all files except "." and
        ;; "..".  This is OK because we manually insert these entries
        ;; in the hash table.
        (string-match
 	"--\\(almost-\\)?all\\>\\|\\(\\`\\| \\)-[[:alpha:]]*[aA]" switches)
+       ;; Allow flags starting with a single dash
        (string-match "\\(\\`\\| \\)-[[:alpha:]]*l" switches)
+       ;; Disallow recursive flag
        (not (string-match
-	     "--recursive\\>\\|\\(\\`\\| \\)-[[:alpha:]]*R" switches))
+	     "\\(\\`\\| \\)-[[:alpha:]]*R" switches))
+       ;; Disallow long flags.
+       (not (string-match "--\\w\\{2,\\}"))
        switches))
 
 (defun ange-ftp-get-files (directory &optional no-error)
-- 
2.1.3