[gvfs/gnome-2-28] Fixed parsing of CMU/VMS-IP FTP style listing (upstream)



commit 81e1695043422607da256f60c8bd306e6d14d33c
Author: Benjamin Otte <otte gnome org>
Date:   Fri Nov 13 22:44:50 2009 +0100

    Fixed parsing of CMU/VMS-IP FTP style listing (upstream)
    
    upstream references:
    http://bugzilla.mozilla.org/show_bug.cgi?id=515583
    http://hg.mozilla.org/mozilla-central/rev/98330c8132a9
    http://hg.mozilla.org/mozilla-central/rev/cade5b705114

 daemon/ParseFTPList.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/daemon/ParseFTPList.c b/daemon/ParseFTPList.c
index 9d4c182..2d2ce0f 100644
--- a/daemon/ParseFTPList.c
+++ b/daemon/ParseFTPList.c
@@ -44,6 +44,13 @@
 
 /* ==================================================================== */
 
+static inline int ParsingFailed(struct list_state *state)
+{
+  if (state->parsed_one || state->lstyle) /* junk if we fail to parse */
+    return '?';      /* this time but had previously parsed successfully */
+  return '"';        /* its part of a comment or error message */
+}
+
 int ParseFTPList(const char *line, struct list_state *state,
                  struct list_result *result )
 {
@@ -122,6 +129,9 @@ int ParseFTPList(const char *line, struct list_state *state,
       }
     }    
 
+    if (!numtoks)
+      return ParsingFailed(state);
+
     linelen_sans_wsp = &(tokens[numtoks-1][toklen[numtoks-1]]) - tokens[0];
     if (numtoks == (sizeof(tokens)/sizeof(tokens[0])) )
     {
@@ -355,11 +365,16 @@ int ParseFTPList(const char *line, struct list_state *state,
               pos++;
               p++;
             }
-            if (lstyle && pos < (toklen[0]-1) && *p == ']')
+            if (lstyle && pos < (toklen[0]-1))
             {
+              /* ']' was found and there is at least one character after it */
+              g_assert (*p == ']');
               pos++;
               p++;
               tokmarker = pos; /* length of leading "[DIR1.DIR2.etc]" */
+            } else {
+              /* not a CMU style listing */
+              lstyle = 0;
             }
           }
           while (lstyle && pos < toklen[0] && *p != ';')
@@ -386,7 +401,7 @@ int ParseFTPList(const char *line, struct list_state *state,
           pos -= tokmarker;      /* => fnlength sans "[DIR1.DIR2.etc]" */
           p = &(tokens[0][tokmarker]); /* offset of basename */
 
-          if (!lstyle || pos > 80) /* VMS filenames can't be longer than that */
+          if (!lstyle || pos == 0 || pos > 80) /* VMS filenames can't be longer than that */
           {
             lstyle = 0;
           }
@@ -1682,9 +1697,7 @@ int ParseFTPList(const char *line, struct list_state *state,
 
   } /* if (linelen > 0) */
 
-  if (state->parsed_one || state->lstyle) /* junk if we fail to parse */
-    return '?';      /* this time but had previously parsed successfully */
-  return '"';        /* its part of a comment or error message */
+  return ParsingFailed(state);
 }
 
 /* ==================================================================== */
@@ -1703,7 +1716,7 @@ static int do_it(FILE *outfile,
   char *p;
   int rc;
 
-  rc = ParseFTPLIST( line, state, &result );
+  rc = ParseFTPList( line, state, &result );
 
   if (!outfile)
   {



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