------------------------------------------------------------ revno: 14174 revision-id: squid3@treenet.co.nz-20170622153146-nxo8vl6a9r8z03v4 parent: squid3@treenet.co.nz-20170621201248-ezpvykg0b307ix61 fixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4671 committer: Amos Jeffries branch nick: 3.5 timestamp: Fri 2017-06-23 03:31:46 +1200 message: Bug 4671 pt3: various GCC 7 compile errors Also, remove limit on FTP realm strings Convert ftpRealm() from generating char* to SBuf. This fixes issues identified by GCC 7 where the realm string may be longer than the available buffer and gets truncated. The size of the buffer was making the occurance rather rare, but it is still possible. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20170622153146-nxo8vl6a9r8z03v4 # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: b54e1a339544443ed9b34a094717b2781c746c76 # timestamp: 2017-06-22 15:50:59 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20170621201248-\ # ezpvykg0b307ix61 # # Begin patch === modified file 'src/DiskIO/DiskThreads/aiops.cc' --- src/DiskIO/DiskThreads/aiops.cc 2017-01-01 00:16:45 +0000 +++ src/DiskIO/DiskThreads/aiops.cc 2017-06-22 15:31:46 +0000 @@ -290,7 +290,7 @@ /* Create threads and get them to sit in their wait loop */ squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t)); - assert(NUMTHREADS); + assert(NUMTHREADS != 0); for (i = 0; i < NUMTHREADS; ++i) { threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc(); === modified file 'src/clients/FtpGateway.cc' --- src/clients/FtpGateway.cc 2017-06-21 19:54:39 +0000 +++ src/clients/FtpGateway.cc 2017-06-22 15:31:46 +0000 @@ -153,8 +153,8 @@ virtual void timeout(const CommTimeoutCbParams &io); void ftpAcceptDataConnection(const CommAcceptCbParams &io); - static HttpReply *ftpAuthRequired(HttpRequest * request, const char *realm); - const char *ftpRealm(void); + static HttpReply *ftpAuthRequired(HttpRequest * request, SBuf &realm); + SBuf ftpRealm(); void loginFailed(void); virtual void haveParsedReplyHeaders(); @@ -1189,7 +1189,8 @@ { if (!checkAuth(&request->header)) { /* create appropriate reply */ - HttpReply *reply = ftpAuthRequired(request, ftpRealm()); + SBuf realm(ftpRealm()); // local copy so SBuf wont disappear too early + HttpReply *reply = ftpAuthRequired(request, realm); entry->replaceHttpReply(reply); serverComplete(); return; @@ -1290,7 +1291,9 @@ #if HAVE_AUTH_MODULE_BASIC /* add Authenticate header */ - newrep->header.putAuth("Basic", ftpRealm()); + // XXX: performance regression. c_str() may reallocate + SBuf realm(ftpRealm()); // local copy so SBuf wont disappear too early + newrep->header.putAuth("Basic", realm.c_str()); #endif // add it to the store entry for response.... @@ -1298,18 +1301,19 @@ serverComplete(); } -const char * +SBuf Ftp::Gateway::ftpRealm() { - static char realm[8192]; + SBuf realm; /* This request is not fully authenticated */ - if (!request) { - snprintf(realm, 8192, "FTP %s unknown", user); - } else if (request->port == 21) { - snprintf(realm, 8192, "FTP %s %s", user, request->GetHost()); - } else { - snprintf(realm, 8192, "FTP %s %s port %d", user, request->GetHost(), request->port); + realm.appendf("FTP %s ", user); + if (!request) + realm.append("unknown", 7); + else { + realm.append(request->GetHost()); + if (request->port != 21) + realm.appendf(" port %d", request->port); } return realm; } @@ -2673,13 +2677,14 @@ } HttpReply * -Ftp::Gateway::ftpAuthRequired(HttpRequest * request, const char *realm) +Ftp::Gateway::ftpAuthRequired(HttpRequest * request, SBuf &realm) { ErrorState err(ERR_CACHE_ACCESS_DENIED, Http::scUnauthorized, request); HttpReply *newrep = err.BuildHttpReply(); #if HAVE_AUTH_MODULE_BASIC /* add Authenticate header */ - newrep->header.putAuth("Basic", realm); + // XXX: performance regression. c_str() may reallocate + newrep->header.putAuth("Basic", realm.c_str()); #endif return newrep; } === modified file 'src/fde.cc' --- src/fde.cc 2017-01-01 00:16:45 +0000 +++ src/fde.cc 2017-06-22 15:31:46 +0000 @@ -85,15 +85,15 @@ char const * fde::remoteAddr() const { - LOCAL_ARRAY(char, buf, MAX_IPSTRLEN ); + static char buf[MAX_IPSTRLEN+7]; // 7 = length of ':port' strings if (type != FD_SOCKET) return null_string; if ( *ipaddr ) - snprintf( buf, MAX_IPSTRLEN, "%s:%d", ipaddr, (int)remote_port); + snprintf(buf, sizeof(buf), "%s:%u", ipaddr, remote_port); else - local_addr.toUrl(buf,MAX_IPSTRLEN); // toHostStr does not include port. + local_addr.toUrl(buf, sizeof(buf)); // toHostStr does not include port. return buf; } === modified file 'src/fs/ufs/RebuildState.cc' --- src/fs/ufs/RebuildState.cc 2017-01-01 00:16:45 +0000 +++ src/fs/ufs/RebuildState.cc 2017-06-22 15:31:46 +0000 @@ -444,7 +444,7 @@ } if (0 == in_dir) { /* we need to read in a new directory */ - snprintf(fullpath, MAXPATHLEN, "%s/%02X/%02X", + snprintf(fullpath, sizeof(fullpath), "%s/%02X/%02X", sd->path, curlvl1, curlvl2); @@ -489,7 +489,7 @@ continue; } - snprintf(fullfilename, MAXPATHLEN, "%s/%s", + snprintf(fullfilename, sizeof(fullfilename), "%s/%s", fullpath, entry->d_name); debugs(47, 3, HERE << "Opening " << fullfilename); fd = file_open(fullfilename, O_RDONLY | O_BINARY); === modified file 'src/fs/ufs/RebuildState.h' --- src/fs/ufs/RebuildState.h 2017-01-01 00:16:45 +0000 +++ src/fs/ufs/RebuildState.h 2017-06-22 15:31:46 +0000 @@ -54,7 +54,7 @@ dirent_t *entry; DIR *td; char fullpath[MAXPATHLEN]; - char fullfilename[MAXPATHLEN]; + char fullfilename[MAXPATHLEN*2]; StoreRebuildData counts; === modified file 'src/gopher.cc' --- src/gopher.cc 2017-01-01 00:16:45 +0000 +++ src/gopher.cc 2017-06-22 15:31:46 +0000 @@ -820,7 +820,7 @@ * This will be called when request write is complete. Schedule read of reply. */ static void -gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size, Comm::Flag errflag, int xerrno, void *data) +gopherSendComplete(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag errflag, int xerrno, void *data) { GopherStateData *gopherState = (GopherStateData *) data; StoreEntry *entry = gopherState->entry; @@ -840,10 +840,6 @@ err->url = xstrdup(entry->url()); gopherState->fwd->fail(err); gopherState->serverConn->close(); - - if (buf) - memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */ - return; } @@ -885,9 +881,6 @@ AsyncCall::Pointer call = commCbCall(5,5, "gopherReadReply", CommIoCbPtrFun(gopherReadReply, gopherState)); entry->delayAwareRead(conn, gopherState->replybuf, BUFSIZ, call); - - if (buf) - memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */ } /** @@ -898,32 +891,31 @@ gopherSendRequest(int fd, void *data) { GopherStateData *gopherState = (GopherStateData *)data; - char *buf = (char *)memAllocate(MEM_4K_BUF); + MemBuf mb; + mb.init(); if (gopherState->type_id == GOPHER_CSO) { const char *t = strchr(gopherState->request, '?'); - if (t != NULL) + if (t) ++t; /* skip the ? */ else t = ""; - snprintf(buf, 4096, "query %s\r\nquit\r\n", t); - } else if (gopherState->type_id == GOPHER_INDEX) { - char *t = strchr(gopherState->request, '?'); - - if (t != NULL) - *t = '\t'; - - snprintf(buf, 4096, "%s\r\n", gopherState->request); + mb.Printf("query %s\r\nquit", t); } else { - snprintf(buf, 4096, "%s\r\n", gopherState->request); + if (gopherState->type_id == GOPHER_INDEX) { + if (char *t = strchr(gopherState->request, '?')) + *t = '\t'; + } + mb.append(gopherState->request, strlen(gopherState->request)); } + mb.append("\r\n", 2); - debugs(10, 5, HERE << gopherState->serverConn); + debugs(10, 5, gopherState->serverConn); AsyncCall::Pointer call = commCbCall(5,5, "gopherSendComplete", CommIoCbPtrFun(gopherSendComplete, gopherState)); - Comm::Write(gopherState->serverConn, buf, strlen(buf), call, NULL); + Comm::Write(gopherState->serverConn, &mb, call); gopherState->entry->makePublic(); } === modified file 'src/icmp/Makefile.am' --- src/icmp/Makefile.am 2017-01-01 00:16:45 +0000 +++ src/icmp/Makefile.am 2017-06-22 15:31:46 +0000 @@ -59,7 +59,8 @@ pinger_LDFLAGS = $(LIBADD_DL) pinger_LDADD=\ libicmp-core.la \ - ../ip/libip.la \ + $(top_builddir)/src/ip/libip.la \ + $(top_builddir)/src/base/libbase.la \ $(COMPAT_LIB) \ $(XTRA_LIBS)