From: serassio <> Date: Wed, 19 Oct 2005 01:10:29 +0000 (+0000) Subject: Bug #1426: Crash in rfc1738_do_escape at rfc1738.c:97 X-Git-Tag: SQUID_3_0_PRE4~582 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5f80edc2be38fa02f5f9d55f72283434fed00c3;p=thirdparty%2Fsquid.git Bug #1426: Crash in rfc1738_do_escape at rfc1738.c:97 Forward port of 2.5 patch. --- diff --git a/src/ftp.cc b/src/ftp.cc index 635034f89d..ac3c0f6f05 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.371 2005/09/15 13:38:45 serassio Exp $ + * $Id: ftp.cc,v 1.372 2005/10/18 19:10:29 serassio Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -563,7 +563,7 @@ ftpListingFinish(FtpStateData * ftpState) if (ftpState->flags.listformat_unknown && !ftpState->flags.tried_nlst) { storeAppendPrintf(e, "[As plain directory]\n", - ftpState->flags.dir_slash ? rfc1738_escape_part(ftpState->filepath) : "."); + ftpState->flags.dir_slash ? rfc1738_escape_part(ftpState->old_filepath) : "."); } else if (ftpState->typecode == 'D') { const char *path = ftpState->flags.dir_slash ? ftpState->filepath : "."; storeAppendPrintf(e, "[As extended directory]\n", html_quote(path)); @@ -915,12 +915,26 @@ ftpHtmlifyListEntry(const char *line, FtpStateData * ftpState) "%2f/", "Root Directory"); } else if (ftpState->flags.no_dotdot && !ftpState->flags.root_dir) { + char *url; /* Normal directory where last component is / or .. */ strcpy(href, "%2e%2e/"); strcpy(text, "Parent Directory"); - snprintf(link, 2048, "(%s)", - !ftpState->flags.dir_slash ? "../" : "./", - "Back"); + + if (ftpState->flags.dir_slash) { + url = xstrdup("./"); + } else { + const char *title = ftpState->title_url.buf(); + int k = 6 + strcspn(&title[6], "/"); + char *t; + url = xstrdup(title + k); + t = url + strlen(url) - 2; + + while (t > url && *t != '/') + *t-- = '\0'; + } + + snprintf(link, 2048, "(%s)", url, "Back"); + safe_free(url); } else { /* NO_DOTDOT && ROOT_DIR */ /* "UNIX Root" directory */ strcpy(href, "/"); @@ -1321,6 +1335,8 @@ ftpCheckUrlpath(FtpStateData * ftpState) if (l == 1) ftpState->flags.root_dir = 1; + } else { + ftpState->flags.dir_slash = 1; } } @@ -2039,11 +2055,10 @@ ftpGetFile(FtpStateData * ftpState) static void ftpListDir(FtpStateData * ftpState) { - if (!ftpState->flags.isdir) { + if (ftpState->flags.dir_slash) { debug(9, 3) ("Directory path did not end in /\n"); ftpState->title_url.append("/"); ftpState->flags.isdir = 1; - ftpState->flags.dir_slash = 1; } ftpSendPasv(ftpState);