[PATCH 8/8] Deal with "\n" vs "\r\n" in FEAT responses.



Researched by Oliver Joos.
---
 daemon/gvfsbackendftp.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/daemon/gvfsbackendftp.c b/daemon/gvfsbackendftp.c
index 7e021f9..1c719cf 100644
--- a/daemon/gvfsbackendftp.c
+++ b/daemon/gvfsbackendftp.c
@@ -641,11 +641,15 @@ ftp_connection_parse_features (FtpConnection *conn)
   char **supported;
   guint i, j;
 
-  supported = g_strsplit (conn->read_buffer, "\r\n", -1);
+  /* The "\n" should really be "\r\n" but we deal with both to handle broken
+   * servers. We strip off '\r' later, if it exists. */
+  supported = g_strsplit (conn->read_buffer, "\n", -1);
 
   for (i = 1; supported[i]; i++)
     {
-      const char *feature = supported[i];
+      char *feature = supported[i];
+      int len;
+
       if (feature[0] != ' ')
 	continue;
 
@@ -654,6 +658,12 @@ ftp_connection_parse_features (FtpConnection *conn)
        */
       while (feature[0] == ' ')
         feature++;
+
+      /* strip off trailing '\r', if it exists. */
+      len = strlen(feature);
+      if (len > 0 && feature[len-1] == '\r')
+	      feature[len-1] = '\0';
+
       for (j = 0; j < G_N_ELEMENTS (features); j++)
 	{
 	  if (g_ascii_strcasecmp (feature, features[j].name) == 0)
-- 
1.5.6.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]