[gvfs] [FTP] Fix fallout from Mozilla upstream merges



commit aede024c51675989b734532a9c4f6b499065bbc1
Author: Benjamin Otte <otte gnome org>
Date:   Mon Aug 10 14:45:50 2009 +0200

    [FTP] Fix fallout from Mozilla upstream merges
    
    Mozilla only strips \r characters when the lines ist terminated with
    \r\n but not when terminated with \r\0, so we strip the line terminator
    ourselves perfore passing the string to ParseFTPList().

 daemon/gvfsftpdircache.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/daemon/gvfsftpdircache.c b/daemon/gvfsftpdircache.c
index 8e6de25..e357edd 100644
--- a/daemon/gvfsftpdircache.c
+++ b/daemon/gvfsftpdircache.c
@@ -508,6 +508,7 @@ g_vfs_ftp_dir_cache_funcs_process (GInputStream *        stream,
   int type;
   GVfsFtpFile *file;
   char *line, *s;
+  gsize length;
 
   /* protect against code reorg - in current code, error never is NULL */
   g_assert (error != NULL);
@@ -516,11 +517,17 @@ g_vfs_ftp_dir_cache_funcs_process (GInputStream *        stream,
   data = g_data_input_stream_new (stream);
   /* we use LF only, because the mozilla code can handle lines ending in CR */
   g_data_input_stream_set_newline_type (data, G_DATA_STREAM_NEWLINE_TYPE_LF);
-  while ((line = g_data_input_stream_read_line (data, NULL, cancellable, error)))
+  while ((line = g_data_input_stream_read_line (data, &length, cancellable, error)))
     {
       struct list_result result = { 0, };
       GTimeVal tv = { 0, 0 };
 
+      /* strip trailing \r - ParseFTPList only removes it if the line ends in \r\n,
+       * but we stripped the \n already.
+       */
+      if (length > 0 && line[length - 1] == '\r')
+        line[--length] = '\0';
+
       g_debug ("<<%2d <<  %s\n", debug_id, line);
       type = ParseFTPList (line, &state, &result);
       if (type != 'd' && type != 'f' && type != 'l')
@@ -551,6 +558,7 @@ g_vfs_ftp_dir_cache_funcs_process (GInputStream *        stream,
       g_free (s);
       if (file == NULL)
         {
+          g_debug ("# invalid filename, skipping");
           g_free (line);
           continue;
         }



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