summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2009-11-13 22:44:50 +0100
committerBenjamin Otte <otte@gnome.org>2009-11-13 22:44:50 +0100
commit24aa2ea08693969d66b263ba2aa9289056b23483 (patch)
tree022fa233280634542b4d9046a56502a6c1a88958 /daemon
parent72d716e37bd8a26361608a69beb60089981dee19 (diff)
downloadgvfs-24aa2ea08693969d66b263ba2aa9289056b23483.tar.gz
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
Diffstat (limited to 'daemon')
-rw-r--r--daemon/ParseFTPList.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/daemon/ParseFTPList.c b/daemon/ParseFTPList.c
index 9d4c1828..2d2ce0f4 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)
{