From: wessels <> Date: Wed, 22 Apr 1998 02:41:20 +0000 (+0000) Subject: Fixed ftpParseListing loop X-Git-Tag: SQUID_3_0_PRE1~3478 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7131112f15c3ae712c31040500b0aeda44a410a8;p=thirdparty%2Fsquid.git Fixed ftpParseListing loop Added full error message to ERR_FTP_FAIL error pages --- diff --git a/src/errorpage.cc b/src/errorpage.cc index f56f686e0b..4004e5a7a6 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.124 1998/03/31 05:37:39 wessels Exp $ + * $Id: errorpage.cc,v 1.125 1998/04/21 20:41:20 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -347,6 +347,7 @@ errorStateFree(ErrorState * err) * E - strerror() x * f - FTP request line x * F - FTP reply line x + * g - FTP server message x * h - cache hostname x * H - server host name x * i - client IP address x @@ -372,6 +373,8 @@ errorConvert(char token, ErrorState * err) request_t *r = err->request; static char buf[CVT_BUF_SZ]; const char *p = buf; + wordlist *w; + int o; switch (token) { case 'B': p = r ? ftpUrlWith2f(r) : "[no URL]"; @@ -399,6 +402,16 @@ errorConvert(char token, ErrorState * err) else p = ""; break; + case 'g': + /* FTP SERVER MESSAGE */ + buf[0] = '\0'; + o = 0; + for (w = err->ftp_server_msg; w; w = w->next) { + o += snprintf(buf + o, CVT_BUF_SZ - o, "%s\n", w->key); + if (o >= CVT_BUF_SZ) + break; + } + break; case 'h': snprintf(buf, CVT_BUF_SZ, "%s", getMyHostname()); break; diff --git a/src/ftp.cc b/src/ftp.cc index 77e98ce838..37018071b3 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.218 1998/04/08 04:23:52 wessels Exp $ + * $Id: ftp.cc,v 1.219 1998/04/21 20:41:21 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -692,7 +692,7 @@ static void ftpParseListing(FtpStateData * ftpState, int len) { char *buf = ftpState->data.buf; - char *sbuf; /* NULL-terminated copy of buf */ + char *sbuf; /* NULL-terminated copy of buf */ char *end; char *line; char *s; @@ -700,29 +700,39 @@ ftpParseListing(FtpStateData * ftpState, int len) size_t linelen; size_t usable; StoreEntry *e = ftpState->entry; + /* + * There may have been 'data.offset' bytes left over from a previous + * call here + */ len += ftpState->data.offset; - end = buf + len - 1; - while (*end != '\r' && *end != '\n' && end > buf) + /* + * We need a NULL-terminated buffer for scanning, ick + */ + sbuf = xmalloc(len + 1); + xstrncpy(sbuf, buf, len + 1); + end = sbuf + len - 1; + while (*end != '\r' && *end != '\n' && end > sbuf) end--; - usable = end - buf; + usable = end - sbuf; if (usable == 0) { debug(9, 3) ("ftpParseListing: didn't find end for %s\n", storeUrl(e)); + xfree(sbuf); return; } + debug(9, 3) ("ftpParseListing: %d bytes to play with\n", len); line = memAllocate(MEM_4K_BUF); end++; - /* XXX, buf needs to be NULL terminated, copying is gross */ - sbuf = xmalloc(len+1); - xstrncpy(sbuf, buf, len+1); storeBuffer(e); - for (s = sbuf; s < end; s += strcspn(s, crlf), s += strspn(s, crlf)) { + for (s = sbuf; s < end; s += strcspn(s, crlf)) { + s += strspn(s, crlf); + debug(9, 3) ("ftpParseListing: s = {%s}\n", s); linelen = strcspn(s, crlf) + 1; if (linelen < 2) break; if (linelen > 4096) linelen = 4096; xstrncpy(line, s, linelen); - debug(9, 7) ("%s\n", line); + debug(9, 7) ("ftpParseListing: {%s}\n", line); if (!strncmp(line, "total", 5)) continue; t = ftpHtmlifyListEntry(line, ftpState); @@ -1160,6 +1170,7 @@ ftpReadControlReply(int fd, void *data) err = errorCon(ERR_FTP_FAILURE, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = 0; err->request = requestLink(ftpState->request); + err->ftp_server_msg = ftpState->ctrl.message; errorAppendEntry(entry, err); } } @@ -2025,6 +2036,7 @@ ftpFail(FtpStateData * ftpState) } err = errorCon(ERR_FTP_FAILURE, HTTP_INTERNAL_SERVER_ERROR); err->request = requestLink(ftpState->request); + err->ftp_server_msg = ftpState->ctrl.message; if (ftpState->old_request) err->ftp.request = ftpState->old_request; else diff --git a/src/structs.h b/src/structs.h index aa4cfcf5e5..27dbe3b537 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1138,6 +1138,7 @@ struct _ErrorState { char *reply; } ftp; char *request_hdrs; + wordlist *ftp_server_msg; }; /*