]> git.ipfire.org Git - thirdparty/squid.git/log
thirdparty/squid.git
7 years agoCollapse security_file_certgen requests.
Christos Tsantilas [Mon, 12 Jun 2017 16:05:59 +0000 (19:05 +0300)] 
Collapse security_file_certgen requests.

Concurrent identical same-worker security_file_certgen (a.k.a. ssl_crtd)
requests are collapsed: The first such request goes through to one of
the helpers while others wait for that first request to complete,
successfully or otherwise. This optimization helps dealing with flash
crowds that suddenly send a large number of HTTPS requests to a small
group of origin servers.

Two certificate generation requests are considered identical if their
on-the-wire images are identical. This simple and fast approach covers
all certificate generation parameters, including all mimicked
certificate properties, and avoids hash collisions and poisoning.
Compared to collision- or poisoning-sensitive approaches that store raw
certificates and compare their signatures or fingerprints, storing
helper queries costs a few extra KB per pending helper request. That
extra RAM cost is worth the advantages and will be eliminated when
helper code switches from c-strings to SBufs.

This is a Measurement Factory project.

7 years agossl::server_name options to control matching logic.
Christos Tsantilas [Mon, 12 Jun 2017 15:40:16 +0000 (18:40 +0300)] 
ssl::server_name options to control matching logic.

Many popular servers use certificates with several "alternative subject
names" (SubjectAltName). Many of those names are wildcards. For example,
a www.youtube.com certificate currently includes *.google.com and 50+
other subject names, most of which are wildcards.

Often, admins want server_name to match any of the subject names. This
is useful to match any server belonging to a large conglomerate of
companies, all including some *.example.com name in their certificates.
The existing server_name functionality addresses this use case well.

The new ACL options address several other important use cases:

--consensus identifies transactions with a particular server when
  server's subject name is also present in certificates used by many other
  servers (e.g., matching transactions with a particular Google server but
  not with all Youtube servers).

--client-requested allows both (a) SNI-based matching even after
  Squid obtains the server certificate and (b) pinpointing a particular
  server in a group of different servers all using the same wildcard
  certificate (e.g., matching appengine.example.com but not
  www.example.com when the certificate for has *.example.com subject).

--server-provided allows matching only after Squid obtains the server
  certificate and matches any of the conglomerate parts.

Also this patch fixes squid to log client SNI when client-first bumping mode
is used too.

This is a Measurement Factory project.

7 years agoSupport for --long-acl-options
Christos Tsantilas [Mon, 12 Jun 2017 14:48:28 +0000 (17:48 +0300)] 
Support for --long-acl-options

The old single-letter ACL "flags" code was refactored to support long option
names (with option-specific value types) without significant
per-ACL-object performance/RAM overheads and without creating a global
registry for all possible options. This refactoring (unexpectedly)
resulted in removal of a lot of unreliable static initialization code.

Refactoring fixed ACL flags parsing code that was dangerously misinterpreting
-i and +i flags in several contexts. For example, each of the three cases
below was misinterpreted as if three domains were configured (e.g., "+i",
"-z", and "example.com") on each line instead of one domain ("example.com"):

        acl parsedAsThreeDomains dstdomain +i -i .example.com
        acl parsedAsThreeDomains dstdomain -i +i .example.com
        acl parsedAsThreeDomains dstdomain +i -z .example.com

TODO: Finish ACL::clone() removal. Then consider removing any unused
ACLData::clone() and associated ACL/ACLData copying methods.

This is a Measurement Factory project.

7 years agoMake GCC v6 happier after r15183. GCC thinks "if (x)" does not use x.
Alex Rousskov [Fri, 9 Jun 2017 18:19:00 +0000 (12:19 -0600)] 
Make GCC v6 happier after r15183. GCC thinks "if (x)" does not use x.

Same as r15186 but applied to tunnel.cc now. I hate code duplication.

7 years agoMake GCC v6 happier after r15183. GCC thinks "if (x)" does not use x.
Alex Rousskov [Fri, 9 Jun 2017 16:59:36 +0000 (10:59 -0600)] 
Make GCC v6 happier after r15183. GCC thinks "if (x)" does not use x.

7 years agoSourceFormat Enforcement
Source Maintenance [Fri, 9 Jun 2017 06:12:19 +0000 (06:12 +0000)] 
SourceFormat Enforcement

7 years agoAttempting to fix Jenkins "make test" (with clang?) after r15183.
Alex Rousskov [Fri, 9 Jun 2017 06:03:47 +0000 (00:03 -0600)] 
Attempting to fix Jenkins "make test" (with clang?) after r15183.

undefined reference: operator<<(std::ostream&, Comm::Connection const&)
make[5]: *** [tests/testACLMaxUserIP] Error 1

My test-builds.sh passed before (and still passes after) this change, so
I am just guessing that I picked the wrong stub_*comm.cc file in r15183.

7 years agoHappy Eyeballs: Use each fully resolved forwarding destination ASAP.
Alex Rousskov [Fri, 9 Jun 2017 04:38:40 +0000 (22:38 -0600)] 
Happy Eyeballs: Use each fully resolved forwarding destination ASAP.

Do not wait for all request forwarding destinations to be resolved. Use
each resolved destination as soon as it is needed. This change does not
improve or affect IPv4/IPv6 handling (Squid still waits for both DNS A
and AAAA answers when resolving a single destination name), but the peer
selection code can now deliver each IP address to the FwdState/tunneling
code without waiting for all other destination names to be DNS-resolved.
TODO: Deliver A and AAAA answers to the peer selection code ASAP.

This change speeds up forwarding in peering environments where peers may
need frequent DNS resolutions but that was not the motivation here.

This change is a step towards a more complete Happy Eyeballs support in
Squid. The general path can be roughly summarized as follows:

1. Squid has already supported: Use parallel A and AAAA queries.
2. This change: ASAP delivery of IPs from peer selection to FwdState.
3. The next step: ASAP delivery of IPs from DNS to peer selection.
4. A separate project may add: Use parallel TCP connections.

Also fixed missing cbdataReferenceDone(psstate->callback_data) calls
in three error handling cases. These cases probably leaked memory.

7 years agoFix missing return after rev.15176
Amos Jeffries [Fri, 9 Jun 2017 03:48:10 +0000 (15:48 +1200)] 
Fix missing return after rev.15176

 Detected by Coverity Scan. Issue 1412064

7 years agoSourceFormat Enforcement
Source Maintenance [Fri, 9 Jun 2017 00:12:17 +0000 (00:12 +0000)] 
SourceFormat Enforcement

7 years agoClarified v5 r15168 code logic. No functionality changes.
Alex Rousskov [Thu, 8 Jun 2017 18:09:28 +0000 (12:09 -0600)] 
Clarified v5 r15168 code logic. No functionality changes.

Detected by Coverity Scan. Issue 1412065 (MISSING_BREAK).

7 years agoSourceFormat Enforcement
Source Maintenance [Wed, 7 Jun 2017 18:12:14 +0000 (18:12 +0000)] 
SourceFormat Enforcement

7 years agoFix build on GCC-4 after rev.15177
Amos Jeffries [Wed, 7 Jun 2017 18:04:08 +0000 (06:04 +1200)] 
Fix build on GCC-4 after rev.15177

7 years agoTLS: Move the remaining SSL_SESSION cache callbacks to security/Session.*.
Amos Jeffries [Wed, 7 Jun 2017 15:57:21 +0000 (03:57 +1200)] 
TLS: Move the remaining SSL_SESSION cache callbacks to security/Session.*.

No GnuTLS additions here, or significant code changes. Most of this is a
straight cut-n-paste. Though it does make the slot lookup to auto in the
if-condition to simplify the callback code and removes some no longer
necessary comments as requested in audit.

7 years agoImprove config parsing of logformat definitions
Amos Jeffries [Wed, 7 Jun 2017 12:20:56 +0000 (00:20 +1200)] 
Improve config parsing of logformat definitions

Squid has for some time ignored custom definitions using the same name
as internally defined formats. And overwritten custom formats when there
was a repeated definition.

* Detect logformat duplicates and produce ERROR message indicating the
  format name, config line and action taken.

* Add some missing FATAL labels on parse abort when access_log has
  multiple logformat= options configured.

* Add missing FATAL error message when logformat lines has no name
  parameter (and thus no tokens either).

* Omit the default "logformat=squid" option from cachemgr config dumps.

7 years agoAdd missing ERROR label on cache_peer_access misconfiguration messages
Amos Jeffries [Tue, 6 Jun 2017 13:36:49 +0000 (01:36 +1200)] 
Add missing ERROR label on cache_peer_access misconfiguration messages

7 years agoSourceFormat Enforcement
Source Maintenance [Mon, 5 Jun 2017 00:12:15 +0000 (00:12 +0000)] 
SourceFormat Enforcement

7 years agoBug 4492: Chunk extension parser is too pedantic.
Alex Rousskov [Sun, 4 Jun 2017 23:45:03 +0000 (17:45 -0600)] 
Bug 4492: Chunk extension parser is too pedantic.

Support HTTP/1 BWS when parsing HTTP and ICAP chunk extensions.
Per RFC 7230 Errata #4667, HTTP parsers MUST parse BWS in chunk-ext.
Per RFC 3507 and its extensions, ICAP agents generate BWS in chunk-ext.

Also discovered that our DelimiterCharacters() in pedantic mode is too
strict for many use cases: Most HTTP syntax rules allow both SP and HTAB
but pedantic DelimiterCharacters() only allows SP. Added
WhitespaceCharacters() to provide the more general set where it is
needed in new code (including BWS), but did not remove excessive
DelimiterCharacters() use.

7 years agoSourceFormat Enforcement
Source Maintenance [Sun, 4 Jun 2017 18:12:06 +0000 (18:12 +0000)] 
SourceFormat Enforcement

7 years agoDo not die silently when dying via std::terminate().
Alex Rousskov [Sun, 4 Jun 2017 15:32:01 +0000 (09:32 -0600)] 
Do not die silently when dying via std::terminate().

Report exception failures that call std::terminate(). Exceptions unwind
stack towards main() and sooner or later get handled/reported by Squid.
However, exception _failures_ just call std::terminate(), which aborts
Squid without the stack unwinding. By default, a std::terminate() call
usually results in a silent Squid process death because some default
std::terminate_handler implementations do not say anything at all while
others write to stderr which Squid redirects to /dev/null by default.

Many different problems trigger std::terminate() calls. Most of them are
rare, but, after the C++11 migration, one category became likely in
Squid: A throwing destructor. Destructors in C++11 are implicitly
"noexcept" by default, and many old Squid destructors might throw.

These reporting changes do not bypass or eliminate any failures.

7 years agoSourceFormat Enforcement
Source Maintenance [Fri, 2 Jun 2017 00:12:13 +0000 (00:12 +0000)] 
SourceFormat Enforcement

7 years agoDo not respond with HTTP/304 to unconditional requests
Eduard Bagdasaryan [Thu, 1 Jun 2017 23:49:09 +0000 (17:49 -0600)] 
Do not respond with HTTP/304 to unconditional requests

... after internal revalidation. The original unconditional HttpRequest
was still marked (and processed) as conditional after internal
revalidation because the original (clear) Last-Modified and ETag values
were not restored (cleared) after the internal revalidation abused them.

TODO: Isolate the code converting the request into conditional one _and_
the code that undoes that conversion, to keep both actions in sync.

7 years agoCollapse internal revalidation requests (SMP-unaware caches), again.
Eduard Bagdasaryan [Thu, 1 Jun 2017 23:34:40 +0000 (17:34 -0600)] 
Collapse internal revalidation requests (SMP-unaware caches), again.

The security fix in v5 r14979 had a negative effect on collapsed
forwarding. All "private" entries were considered automatically
non-shareable among collapsed clients. However this is not true: there
are many situations when collapsed forwarding should work despite of
"private" entry status: 304/5xx responses are good examples of that.
This patch fixes that by means of a new StoreEntry::shareableWhenPrivate
flag.

The suggested fix is not complete: To cover all possible situations, we
need to decide whether StoreEntry::shareableWhenPrivate is true or not
for all contexts where StoreEntry::setPrivateKey() is used. This patch
fixes only few important cases inside http.cc, making CF (as well
collapsed revalidation) work for some [non-cacheable] response status
codes, including 3xx, 5xx and some others.

The original support for internal revalidation requests collapsing
was in trink r14755 and referred to Squid bugs 2833, 4311, and 4471.

7 years agoPrep for 4.0.20 and 3.5.26
Amos Jeffries [Thu, 1 Jun 2017 12:10:54 +0000 (00:10 +1200)] 
Prep for 4.0.20 and 3.5.26

7 years agoCleanup: remove some unnecessary wrapper code in libauth.la
Amos Jeffries [Wed, 31 May 2017 03:03:31 +0000 (15:03 +1200)] 
Cleanup: remove some unnecessary wrapper code in libauth.la

Resolves two outstanding "TODO: remove wrapper" items.

* authenticateAddTrailer was completely unused.

* authenticateFixHeader was used but needless.

Also, makes the addReplyAuthHeader static start with upper-case
to comply with Squid coding guidelines.

7 years agoBug 4687: Wrong names of components in man page, section SEE ALSO
Luboš Uhliarik [Mon, 29 May 2017 15:50:02 +0000 (03:50 +1200)] 
Bug 4687: Wrong names of components in man page, section SEE ALSO

7 years agoTranslations: update .po and .pot to latest texts
Amos Jeffries [Mon, 29 May 2017 11:02:04 +0000 (23:02 +1200)] 
Translations: update .po and .pot to latest texts

Also, update the updater script for new helper locations after squid-4-14516

And fix one typo in the purge.8 manual.

7 years agoFix X509_up_ref build errors after r15160
Amos Jeffries [Mon, 29 May 2017 09:41:26 +0000 (21:41 +1200)] 
Fix X509_up_ref build errors after r15160

7 years agoTLS: recognise tls:: namespace on logformat tokens
Amos Jeffries [Mon, 29 May 2017 09:09:54 +0000 (21:09 +1200)] 
TLS: recognise tls:: namespace on logformat tokens

For forward-compatibility with the codes when they switch to TLS naming.
Leaving undocumented until that change actually happens.

7 years agoAdd OpenSSL library details to -v output
Amos Jeffries [Mon, 29 May 2017 00:06:55 +0000 (12:06 +1200)] 
Add OpenSSL library details to -v output

This is partially to meet the OpenSSL copyright requirement that binaries
mention when they are using the library, and partially for admin to see
which library their Squid is using when multiple are present in the system.

7 years agoBug 4662 pt4: better *_up_ref() detection
Amos Jeffries [Mon, 29 May 2017 00:03:34 +0000 (12:03 +1200)] 
Bug 4662 pt4: better *_up_ref() detection

Also, removes duplicate X509_up_ref definition in ssl/support.h

Also, updates LIBS for feature detect with custom library locations

7 years agoBug 4662 pt3: feature detect OpenSSL 1.1 const changes
Amos Jeffries [Sat, 27 May 2017 05:24:31 +0000 (17:24 +1200)] 
Bug 4662 pt3: feature detect OpenSSL 1.1 const changes

7 years agoBug 4662 pt2: feature detect OpenSSL 1.1 API functions
Amos Jeffries [Sat, 27 May 2017 01:03:47 +0000 (13:03 +1200)] 
Bug 4662 pt2: feature detect OpenSSL 1.1 API functions

7 years agoBug 4662: pt1: Feature detect the OpenSSL TLS_method() and similar functions
Amos Jeffries [Fri, 26 May 2017 20:55:48 +0000 (08:55 +1200)] 
Bug 4662: pt1: Feature detect the OpenSSL TLS_method() and similar functions

7 years agoSourceFormat Enforcement
Source Maintenance [Thu, 25 May 2017 18:12:07 +0000 (18:12 +0000)] 
SourceFormat Enforcement

7 years agoFixed Windows-specific code in r15148. Polished r15148 code.
Alex Rousskov [Thu, 25 May 2017 15:35:25 +0000 (09:35 -0600)] 
Fixed Windows-specific code in r15148. Polished r15148 code.

The Windows-specific part of File::synchronize() missed a curly brace.
Besides breaking compilation on Windows, it broke non-Windows code
formatting (--ignore-all-space is advised when looking at this commit).

Also polished r15148 code without changing its functionality. These
polishing touches were meant to be done during r15148 commit.

7 years agoSourceFormat Enforcement
Source Maintenance [Thu, 25 May 2017 06:12:04 +0000 (06:12 +0000)] 
SourceFormat Enforcement

7 years agoBug 4722: eCAP compile errors after v5 r15147
Amos Jeffries [Thu, 25 May 2017 05:27:08 +0000 (17:27 +1200)] 
Bug 4722: eCAP compile errors after v5 r15147

7 years agoSquid crashes when server-first bumping mode is used with openSSL-1.1.0 release
Christos Tsantilas [Wed, 24 May 2017 09:02:40 +0000 (12:02 +0300)] 
Squid crashes when server-first bumping mode is used with  openSSL-1.1.0 release

When OpenSSL-1.1.0 or later is used:
  - The SQUID_USE_SSLGETCERTIFICATE_HACK configure test is false
  - The SQUID_SSLGETCERTIFICATE_BUGGY configure test is true
  - Squid hits an assert(0) inside Ssl::verifySslCertificate when trying to
    retrieve a generated certificate from cache.

This is a Measurement Factory project

7 years agoSourceFormat Enforcement
Source Maintenance [Tue, 23 May 2017 12:12:15 +0000 (12:12 +0000)] 
SourceFormat Enforcement

7 years agoUse Http::ProtocolVersion in config parsing
Amos Jeffries [Tue, 23 May 2017 10:35:48 +0000 (22:35 +1200)] 
Use Http::ProtocolVersion in config parsing

7 years agoCreate PID file ASAP, before the shared memory segments.
Eduard Bagdasaryan [Tue, 23 May 2017 08:45:16 +0000 (20:45 +1200)] 
Create PID file ASAP, before the shared memory segments.

PID file is created right after configuration finalization, before the
allocation for any shared memory segments.

Late PID file creation allowed N+1 concurrent Squid instances to create
the same set of shared segments (overwriting each other segments),
resulting in extremely confusing havoc because the N instances would
later lose the race for the PID file (or some other critical resource)
creation and remove the segments. If that removal happened before a kid
of the single surviving instance started, that kid would fail to start
with open() errors in Segment.cc because the shared segment it tries to
open would be gone. Otherwise, that kid would fail to _restart_ after
any unrelated failures (possibly many days after the conflict), with
same errors, for the same reason.

Shared state corruption was also possible if different kids (of the
winning instance) opened (and started using) segments created (and
initialized) by different instances.

Situations with N+1 concurrent Squid instances are not uncommon because
many Squid service management scripts (or manual admin commands!)
* do not check whether another Squid is already running and/or
* incorrectly assume that "squid -z" does not daemonize.

This change finally makes starting N+1 Squid instances safe (AFAIK).

Also made daemonized and non-daemonized Squid create the PID file at the
same startup stage, reducing inconsistencies between the two modes.

7 years agoMake PID file check/creation atomic to avoid associated race conditions.
Eduard Bagdasaryan [Tue, 23 May 2017 08:31:54 +0000 (20:31 +1200)] 
Make PID file check/creation atomic to avoid associated race conditions.

After this change, if N Squid instances are concurrently started shortly
after time TS, then exactly one Squid instance (X) will run (and have
the corresponding PID file). If another Squid instance has already been
running (with the corresponding PID file) at TS, then X will be that
"old" Squid instance. If no Squid instances were running at TS, then X
will be one of those new N Squids started after TS.

Lack of atomic PID file operations caused unexpected Squid behavior:
* Mismatch between started Squid instance and stored PID file.
* Unexpected crashes due to failed allocation of shared resources,
  such as listening TCP ports or shared memory segments.

A new File class guarantees atomic PID file operations using locks. We
tried to generalize/reuse Ssl::Lock from the certificate generation
helper, but that was a bad idea: Helpers cannot use a lot of Squid code
(e.g., debugs(), TextException, SBuf, and enter_suid()), and the old
Ssl::Lock class cannot support shared locking without a major rewrite.

File locks on Solaris cannot work well (see bug #4212 comment #14), but
those problems do not affect PID file management code. Solaris- and
Windows-specific File code has not been tested and may not build.

Failure to write a PID file is now fatal. It used to be fatal only when
Squid was started with the -C command line option. In the increasingly
SMP world, running without a PID file leads to difficult-to-triage
errors. An admin who does not care about PID files should disable them.

Squid now exits with a non-zero error code if another Squid is running.

Also removed PID file rewriting during reconfiguration in non-daemon
mode. Squid daemons do not support PID file reconfiguration since trunk
r13867, but that revision (accidentally?) left behind half-broken
reconfiguration code for non-daemon mode. Fixing that code is difficult,
and supporting PID reconfigure in non-daemons is probably unnecessary.

Also fixed "is Squid running?" check when kill(0) does not have
permissions to signal the other instance. This does happen when Squid is
started (e.g., on the command line) by a different user than the user
Squid normally runs as or, perhaps, when the other Squid instance enters
a privileged section at the time of the check (untested). The bug could
result in undelivered signals or multiple running Squid instances.

These changes do not alter partially broken enter/leave_suid() behavior
of main.cc. That old code will need to be fixed separately!

PID file-related cache.log messages have changed slightly to improve
consistency with other DBG_IMPORTANT messages and to simplify code.
Squid no longer lies about creating a non-configured PID file. TODO:
Consider lowering the importance of these benign/boring messages.

* Terminal errors should throw instead of calling exit()

Squid used to call exit() in many PID-related error cases. Using exit()
as an error handling mechanism creates several problems:

1. exit() does not unwind the stack, possibly executing atexit()
   handlers in the wrong (e.g., privileged) context, possibly leaving
   some RAII-controller resources in bad state, and complicating triage;
2. Using exit() complicates code by adding a yet another error handling
   mechanism to the (appropriate) exceptions and assertions.
3. Spreading exit() calls around the code obscures unreachable code
   areas, complicates unifying exit codes, and confuses code checkers.

Long-term, it is best to use exceptions for nearly all error handling.
Reaching that goal will take time, but we can and should move in that
direction: The adjusted SquidMainSafe() treats exceptions as fatal
errors, without dumping core or assuming that no exception can reach
SquidMainSafe() on purpose. This trivial-looking change significantly
simplified (and otherwise improved) PID-file handling code!

The fatal()-related code suffers from similar (and other) problems, but
we did not need to touch it.

TODO: Audit catch(...) and exit() cases [in main.cc] to take advantage
of the new SquidMainSafe() code supporting the throw-on-errors approach.

7 years agoReplace String with SBuf for storage of header names in HttpHeaderEntry
Amos Jeffries [Tue, 23 May 2017 06:46:26 +0000 (18:46 +1200)] 
Replace String with SBuf for storage of header names in HttpHeaderEntry

In the process we gain SBuf methods for delByName and hasNamed.
Deprecating the char* versions.

7 years agoTests: Add stub_url.cc
Amos Jeffries [Tue, 23 May 2017 06:17:35 +0000 (18:17 +1200)] 
Tests: Add stub_url.cc

7 years agoDo not unconditionally revive dead peers after a DNS refresh.
Alex Rousskov [Mon, 22 May 2017 16:49:36 +0000 (10:49 -0600)] 
Do not unconditionally revive dead peers after a DNS refresh.

Every hour, peerRefreshDNS() performs a DNS lookup of all cache_peer
addresses. Before this patch, even if the lookup results did not change,
the associated peerDNSConfigure() code silently cleared dead peer
marking (CachePeer::tcp_up counter), if any.  Forcefully reviving dead
peers every hour can lead to transaction delays (and delays may lead to
failures) due to connection timeouts when using a still dead peer.

This patch starts standard TCP probing (instead of pointless dead peer
reviving), correctly refreshing peer state.  The primary goal is to
cover a situation where a DNS refresh changes the peer address list.
However, TCP probing may be useful for other situations as well and has
low overhead (that is why it starts unconditionally). For example,
probing may be useful when the DNS refresh changes the order of IP
addresses. It also helps detecting dead idle peers.

Also delay and later resume peer probing if peerDNSConfigure() is
invoked when peers are being probed. Squid should re-probe because the
current probes may use stale IP addresses and produce wrong results.

7 years agoFixed xstrndup() documentation, callers. Disclosed implementation bugs.
Alex Rousskov [Mon, 22 May 2017 16:42:28 +0000 (10:42 -0600)] 
Fixed xstrndup() documentation, callers. Disclosed implementation bugs.

xstrndup() does not work like strndup(3), and some callers got confused:

1. When n is the str length or less, standard strndup(str,n) copies all
   n bytes but our xstrndup(str,n) drops the last one. Thus, all callers
   must add one to the desired result length when calling xstrndup().
   Most already do, but it is often hard to see due to low code quality
   (e.g., one must remember that MAX_URL is not the maximum URL length).

2. xstrndup() also assumes that the source string is 0-terminated. This
   dangerous assumption does not contradict many official strndup(3)
   descriptions, but that lack of contradiction is actually a recently
   fixed POSIX documentation bug (i.e., correct implementations must not
   assume 0-termination): http://austingroupbugs.net/view.php?id=1019

The OutOfBoundsException bug led to truncated exception messages.

The ESI bug led to truncated 'literal strings', but I do not know what
that means in terms of user impact. That ESI fix is untested.

cachemgr.cc bug was masked by the fact that the buffer ends with \n
that is unused and stripped by the custom xstrtok() implementation.

TODO. Fix xstrndup() implementation (and rename the function so that
fixed callers do not misbehave if carelessly ported to older Squids).

7 years agoFix missong ERROR label on template loading errors
Amos Jeffries [Fri, 19 May 2017 13:37:24 +0000 (01:37 +1200)] 
Fix missong ERROR label on template loading errors

7 years agoBug 4653 - %st lies about tunneled traffic volumes
Christos Tsantilas [Thu, 18 May 2017 17:21:45 +0000 (20:21 +0300)] 
Bug 4653 - %st lies about tunneled traffic volumes

Squid-5 and squid-4 does not count the "HTTP/1.1 200 Connection Established"
header size for %<st formatting code.

This is a Measurement Factory project

7 years agoSourceFormat Enforcement
Source Maintenance [Tue, 16 May 2017 18:12:17 +0000 (18:12 +0000)] 
SourceFormat Enforcement

7 years agoCleanup: convert AccessLogEntry and sub-classes to C++11 initialization
Amos Jeffries [Tue, 16 May 2017 16:15:07 +0000 (04:15 +1200)] 
Cleanup: convert AccessLogEntry and sub-classes to C++11 initialization

7 years agoAdd 'has' ACL
Eduard Bagdasaryan [Tue, 16 May 2017 14:27:49 +0000 (02:27 +1200)] 
Add 'has' ACL

This ACL detects presence of request, response or ALE transaction
components. Since many ACLs require some of these components, lack of
them in a transaction may spoil the check and confuse admin with
warnings like "... ACL is used in context without an HTTP request".
Using 'has' ACL should help dealing with these problems caused by
component-less transactions.

Also: addressed TODO in item #3 of v4 revision 14752.

7 years agoCleanup: remove SquidString from URI Scheme unit tests
Amos Jeffries [Tue, 16 May 2017 11:52:36 +0000 (23:52 +1200)] 
Cleanup: remove SquidString from URI Scheme unit tests

7 years agoBug 3772: message from FTP server gets mangled
Rainer Tammer [Tue, 16 May 2017 06:48:07 +0000 (18:48 +1200)] 
Bug 3772: message from FTP server gets mangled

7 years agoBug 3102: FTP directory listing drops fist character of file names
Martin von Gagern [Tue, 16 May 2017 06:38:36 +0000 (18:38 +1200)] 
Bug 3102: FTP directory listing drops fist character of file names

7 years agoImprove formatting of several manual pages.
Francesco Chemolli [Thu, 11 May 2017 21:05:51 +0000 (22:05 +0100)] 
Improve formatting of several manual pages.
Thanks to Ingo Schwarze for the contribution.

7 years agobug 4321: ssl_bump terminate does not terminate at step1
Christos Tsantilas [Sun, 7 May 2017 21:53:15 +0000 (00:53 +0300)] 
bug 4321: ssl_bump terminate does not terminate at step1

The following trivial configuration should terminate all connections that
are subject to SslBumping:
  ssl_bump terminate all
but Squid either splices or bumps instead.

This patch fixes Squid to immediately close the connection.

Also this patch:
 - solves wrong use of Ssl::bumpNone in cases where the Ssl::bumpEnd
   (do not bump) or Ssl::bumpSplice (splice after peek/stare at step1)
   must be used.
 - updates %ssl::bump_mode documetation.
 - fixes %ssl::bump_mode formating code to print last bumping action

This is a Measurement Factory project

7 years agoDo not forward HTTP requests to dead idle peers.
Eduard Bagdasaryan [Fri, 5 May 2017 19:42:51 +0000 (13:42 -0600)] 
Do not forward HTTP requests to dead idle peers.

Squid does not forward HTTP transactions to dead peers except when a
dead peer was idle for some time (ten peer connect timeouts or longer).
When the idle peer is still dead, this exception leads to transaction
delays (at best) or client disconnects/errors (at worst), depending on
Squid and client configurations/state. I am removing this exception.

The "use dead idle peer" heuristic was introduced as a small part of a
much bigger bug #14 fix (trunk r6631). AFAICT, the stated goal of the
feature was speeding up failure recovery: The heuristic may result in
HTTP transactions sent to a previously dead (but now alive) idle peer
earlier, before the peer is proven to be alive (using peer revival
mechanisms such as TCP probes). However, the negative side effects of
this heuristic outweigh its accidental benefits. If somebody needs Squid
to detect revived idle peers earlier, they need to add a different
probing mechanism that does not jeopardize HTTP transactions.

Nobody has spoken in defense of this feature on Squid mailing lists:
http://lists.squid-cache.org/pipermail/squid-users/2017-March/014785.html
http://lists.squid-cache.org/pipermail/squid-dev/2017-March/008308.html

The removed functionality was not used to detect revived peers. All peer
revival mechanisms (such as TCP probes) remain intact.

7 years agoReduced the chance of using an absent HttpHdrCc directive value.
Eduard Bagdasaryan [Fri, 5 May 2017 19:23:07 +0000 (13:23 -0600)] 
Reduced the chance of using an absent HttpHdrCc directive value.

Also reduced code duplication inside HttpReply::hdrExpirationTime().

7 years agobug 4711: SubjectAlternativeNames is missing in some generated certificates
Christos Tsantilas [Thu, 4 May 2017 15:28:36 +0000 (18:28 +0300)] 
bug 4711: SubjectAlternativeNames is missing in some generated certificates

Squid may generate certificates which have a Common Name, but do not have
a subjectAltName extension. For example when squid generated certificates
do not mimic an origin certificate or when the certificate adaptation
algorithm sslproxy_cert_adapt/setCommonName is used.

This is causes problems to some browsers, which validates a certificate using
the SubjectAlternativeNames but ignore the CommonName field.

This patch fixes squid to always add a SubjectAlternativeNames extension in
generated certificates which do not mimic an origin certificate.

Squid still will not add a subjectAltName extension when mimicking an origin
server certificate, even if that origin server certificate does not include
the subjectAltName extension. Such origin server may have problems when
talking directly to browsers, and patched Squid is not trying to fix those
problems.

This is a Measurement Factory project

7 years agoSourceFormat Enforcement
Source Maintenance [Wed, 3 May 2017 18:12:07 +0000 (18:12 +0000)] 
SourceFormat Enforcement

7 years agobug4682: When client-first bumping mode is used squid can ignore http access
Christos Tsantilas [Wed, 3 May 2017 14:43:59 +0000 (17:43 +0300)] 
bug4682: When client-first bumping mode is used squid can ignore http access
denied

Squid fails to identify HTTP requests which are tunneled inside an already
established client-first bumped tunnel, and this is results to ignore
http access denied for these requests.

This is a Measurement Factory project

7 years agoFix ssl_bump "bump" action documentation
Christos Tsantilas [Wed, 3 May 2017 14:37:53 +0000 (17:37 +0300)] 
Fix ssl_bump "bump" action documentation

Fixes squid documentation to correctly describe the squid behavior  when the
"bump" action is selected on step SslBump1. In this case squid selects
the client-first bumping mode.

This is a Measurement Factory project

7 years agoBug 4659 - sslproxy_foreign_intermediate_certs does not work
Christos Tsantilas [Sat, 29 Apr 2017 16:19:15 +0000 (19:19 +0300)] 
Bug 4659 - sslproxy_foreign_intermediate_certs does not work

The sslproxy_foreign_intermediate_certs directive does not work after r14769.
The bug is caused because of wrong use of X509_check_issued OpenSSL API call.

This is Measurement Factory project

7 years agoext_time_quota_acl: Add compile test to check dbopen() builds
Amos Jeffries [Thu, 20 Apr 2017 20:27:54 +0000 (08:27 +1200)] 
ext_time_quota_acl: Add compile test to check dbopen() builds

7 years agoBug 4589: ssl_crtd: returning zero on failure
Amos Jeffries [Tue, 18 Apr 2017 12:40:34 +0000 (00:40 +1200)] 
Bug 4589: ssl_crtd: returning zero on failure

7 years agoext_session_acl: cope with new logformat inputs
Amos Jeffries [Mon, 17 Apr 2017 21:36:36 +0000 (09:36 +1200)] 
ext_session_acl: cope with new logformat inputs

Now that Squid is sending an explicit '-' for the trailing %DATA parameter
if there were no acl parameters this helper needs to cope with it on
'active mode' session lookups when login/logout are not being performed.

7 years agoCleanup: remove C++ version 11+ macro checks
Amos Jeffries [Mon, 17 Apr 2017 21:24:33 +0000 (09:24 +1200)] 
Cleanup: remove C++ version 11+ macro checks

This version of Squid requires a C++11 compiler, so the conditional will always be true

7 years agoFix missing initialization in r15120
Amos Jeffries [Fri, 14 Apr 2017 14:35:11 +0000 (02:35 +1200)] 
Fix missing initialization in r15120

 Detected by Coverity Scan. Issue 1405101

7 years agoSecond adaptation missing for CONNECTs
Christos Tsantilas [Fri, 14 Apr 2017 09:27:23 +0000 (12:27 +0300)] 
Second adaptation missing for CONNECTs

Squid does not send CONNECT request to adaptation services
if the "ssl_bump splice" rule matched at step 2. This adaptation
is important because the CONNECT request gains SNI information during
the second SslBump step. This is a regression bug, possibly caused by
the Squid bug 4529 fix (trunk commits r14913 and r14914).

This is a Measurement Factory project.

7 years agoCount failures and use peer-specific connect timeouts when tunneling.
Eduard Bagdasaryan [Wed, 12 Apr 2017 23:34:50 +0000 (11:34 +1200)] 
Count failures and use peer-specific connect timeouts when tunneling.

Fixed two bugs with tunneling CONNECT requests (or equivalent traffic)
through a cache_peer:

1. Not detecting dead cache_peers due to missing code to count peer
   connect failures. TLS/SSL-level failures were detected (for "tls"
   cache_peers) but TCP/IP connect(2) failures were not (for all peers).

2. Origin server connect_timeout used instead of peer_connect_timeout or
   a peer-specific connect-timeout=N (where configured).

The regular forwarding code path does not have the above bugs. This
change reduces code duplication across the two code paths (that
duplication probably caused these bugs in the first place), but a lot
more work is needed in that direction.

The 5-second forwarding timeout hack has been in Squid since
forward_timeout inception (r6733). It is not without problems (now
marked with an XXX), but I left it as is to avoid opening another
Pandora box. The hack now applies to the tunneling code path as well.

7 years agoBug 4695: squidpurge: GCC 7 build errors
Lubos Uhliarik [Wed, 12 Apr 2017 03:12:29 +0000 (15:12 +1200)] 
Bug 4695: squidpurge: GCC 7 build errors

7 years agoCleanup: convert ACLIntRange loops to range-for
Amos Jeffries [Wed, 12 Apr 2017 00:07:55 +0000 (12:07 +1200)] 
Cleanup: convert ACLIntRange loops to range-for

7 years agoCleanup: remove redundant IntRange class from StoreMeta.cc
Amos Jeffries [Wed, 12 Apr 2017 00:00:22 +0000 (12:00 +1200)] 
Cleanup: remove redundant IntRange class from StoreMeta.cc

Use the Range<> template we have for generic ranges.

Move the Range.h template definitio to src/base/. It is only used by
code in src/.

Also, include a small performance improvements for StoreMeta::validLength().
Storing the valid TLV length limits in a static instead of generating a
new object instance on each call.

7 years agoRevert r15115
Amos Jeffries [Mon, 10 Apr 2017 04:12:10 +0000 (16:12 +1200)] 
Revert r15115

Seems I missed something vital in the testing of this.

7 years agoQA: allow test-suite to be run without a full build
Amos Jeffries [Sun, 9 Apr 2017 11:05:48 +0000 (23:05 +1200)] 
QA: allow test-suite to be run without a full build

The squid.conf processing tests have been assuming a full 'make check' was
run and generated a squid binary in the build directory.

This change allows callers to also run these tests on an arbitrary 'squid'
binary by using the command:
  make --eval="BIN_DIR=/path" -C test-suite squid-conf-tests

where /path is the path under which a squid binary already exists.

7 years agoBug 4696: move semantics regression to String class
Amos Jeffries [Sat, 8 Apr 2017 12:02:27 +0000 (00:02 +1200)] 
Bug 4696: move semantics regression to String class

7 years agoBug 4692: SslBump breaks intercepted IPv6 connections
Trever Adams [Thu, 6 Apr 2017 16:48:50 +0000 (04:48 +1200)] 
Bug 4692: SslBump breaks intercepted IPv6 connections

7 years agoCleanup: convert ByteCounter to C++11 initialization
Amos Jeffries [Mon, 3 Apr 2017 09:31:50 +0000 (21:31 +1200)] 
Cleanup: convert ByteCounter to C++11 initialization

7 years agoCleanup: convert class Client to C++11 initialization
Amos Jeffries [Mon, 3 Apr 2017 07:22:32 +0000 (19:22 +1200)] 
Cleanup: convert class Client to C++11 initialization

7 years agoCleanup: make Client::request a Pointer
Amos Jeffries [Sun, 2 Apr 2017 12:06:21 +0000 (00:06 +1200)] 
Cleanup: make Client::request a Pointer

7 years agoCleanup: make ident parameter for FilledChecklist optional
Amos Jeffries [Sun, 2 Apr 2017 12:05:34 +0000 (00:05 +1200)] 
Cleanup: make ident parameter for FilledChecklist optional

7 years agoPrep for 4.0.19 and 3.5.25
Amos Jeffries [Sun, 2 Apr 2017 07:38:18 +0000 (19:38 +1200)] 
Prep for 4.0.19 and 3.5.25

7 years agoAdd move semantics to String class
Amos Jeffries [Sat, 1 Apr 2017 16:46:01 +0000 (04:46 +1200)] 
Add move semantics to String class

Improves speed in several common header code paths using String.

Detected by Coverity Scan. Issue 1364732.

7 years agoCleaup: Convert Format token group names to SBuf
Amos Jeffries [Sat, 1 Apr 2017 16:40:56 +0000 (04:40 +1200)] 
Cleaup: Convert Format token group names to SBuf

7 years agoBug 4610: cleanup of BerkleyDB related checks
Amos Jeffries [Fri, 31 Mar 2017 18:43:20 +0000 (07:43 +1300)] 
Bug 4610: cleanup of BerkleyDB related checks

Most of the logic seems to be hangovers from when session helper was
using the BerkleyDB v1.85 compatibility interface. Some of it is
possibly still necessary for the time_quota helper, but that helper has
not been using it so far and needs an upgrade to match what happened to
session helper.

Changes:

* The helpers needing -ldb will not be built unless the library and
headers are available. So we can drop the Makefile LIB_DB substitutions
and always just link -ldb explicitly to these helpers.

NP: Anyone who needs small minimal binaries, can build with the
--as-needed linker flag, or without these helpers. This change has no
effect on other helpers or the main squid binary.

* Since we no longer need to check if -ldb is necessary, we can drop the
configure.ac and acinclude logic detecting that.

* Remove unused AC_CHECK_DECL(dbopen, ...)
 - resolves one "FIXME"

* Fix the time_quota helper check to only scan db.h header file contents
if that file is existing, and if the db_185.h file is not being used
instead.

* Fix the session helper check to only try compiling with the db.h
header if that header actually exists.

* De-duplicate the library header file detection shared by configure.ac
and the helpers required.m4 files (after the above two changes).

* Remove unused DBLIB variable from configure.ac.

7 years agoFix appending Http::HdrType::VIA code duplication
Eduard Bagdasaryan [Thu, 23 Mar 2017 12:55:36 +0000 (00:55 +1200)] 
Fix appending Http::HdrType::VIA code duplication

... resolving Via header truncation at 1024 bytes.

Also fixes the generated Via values for non-HTTP protocols.

7 years agoBug 4688: various typo error(s) in man page(s)
Lubos Uhliarik [Wed, 22 Mar 2017 05:04:41 +0000 (17:04 +1200)] 
Bug 4688: various typo error(s) in man page(s)

7 years agoCleanup: convert CachePeer to C++11 initialization
amos@georgia.treenetnz.com [Sat, 18 Mar 2017 09:41:16 +0000 (22:41 +1300)] 
Cleanup: convert CachePeer to C++11 initialization

7 years agoCleanup: convert netdbExchangeState to C++11 initialization
amos@georgia.treenetnz.com [Sat, 18 Mar 2017 07:43:03 +0000 (20:43 +1300)] 
Cleanup: convert netdbExchangeState to C++11 initialization

7 years agoAdd move semantics to remaining HTTP Parser heirarchy
Amos Jeffries [Sat, 18 Mar 2017 04:25:24 +0000 (17:25 +1300)] 
Add move semantics to remaining HTTP Parser heirarchy

Destructor is requied because this hierarchy contains virtuals, which in turn
means the compiler will not add move constructor by default. So we must add
teh default ones in ourselves.

  Detected by Coverity Scan. Issues 1364733 and 1364736.

7 years agoSourceFormat Enforcement
Source Maintenance [Fri, 17 Mar 2017 12:12:04 +0000 (12:12 +0000)] 
SourceFormat Enforcement

7 years agoDetail swapfile header inconsistencies.
Eduard Bagdasaryan [Fri, 17 Mar 2017 07:44:27 +0000 (20:44 +1300)] 
Detail swapfile header inconsistencies.

Squid may fail to load cache entry metadata for several very different
reasons, including the following two relatively common ones:

* A cache_dir entry corruption.
* Huge cache_dir entry metadata that does not fit into the I/O buffer
  used for loading entry metadata.

Knowing the exact failure reason may help triage and guide development.
We refactored existing checks to distinguish various error cases,
including the two above. Refactoring also reduced code duplication.

These improvements also uncovered and fixed a null pointer dereference
inside ufsdump.cc (but ufsdump does not even build right now for reasons
unrelated to these changes).

7 years agolibtrie: Fix 'make check' when run before 'make all'
Amos Jeffries [Fri, 17 Mar 2017 01:40:10 +0000 (14:40 +1300)] 
libtrie: Fix 'make check' when run before 'make all'

7 years agoDocs: update refresh_pattern description regarding 'max' option
Garri Djavadyan [Thu, 16 Mar 2017 07:52:37 +0000 (20:52 +1300)] 
Docs: update refresh_pattern description regarding 'max' option

7 years agoCleanup: Migrate Http1:: Parser child classes to C++11 initialization
Amos Jeffries [Wed, 15 Mar 2017 15:41:41 +0000 (04:41 +1300)] 
Cleanup: Migrate Http1:: Parser child classes to C++11 initialization

Also, add move semantics to Http1::RequestParser. This apparently will
make the clear() operators faster as they no longer have to data-copy.
At least, one the base Parser class supports move as well.

It also consists a small experiment to see if virtaul destructor alone
allows automatic move constructor to be added by the compiler.

7 years agoAdd move semantics to Security::ServerOptions and Security::PeerOptions
Amos Jeffries [Sat, 11 Mar 2017 16:33:07 +0000 (05:33 +1300)] 
Add move semantics to Security::ServerOptions and Security::PeerOptions

This apparently will make the clear() operators faster as they no longer
have to data-copy.

  Detected by Coverity Scan. Issues 1364734 and 1364737

7 years agoSourceFormat Enforcement
Source Maintenance [Sat, 11 Mar 2017 00:12:13 +0000 (00:12 +0000)] 
SourceFormat Enforcement

7 years agoBug 4680: Memory leak in v5 r15076
Amos Jeffries [Fri, 10 Mar 2017 18:12:05 +0000 (07:12 +1300)] 
Bug 4680: Memory leak in v5 r15076

Convrts the Http::Message lock/unlock macros to inline functions so the compiler can
catch this type of regression in future Pointer updates

7 years agoDocs: fix typo in rev.15082
Amos Jeffries [Sun, 5 Mar 2017 06:46:20 +0000 (19:46 +1300)] 
Docs: fix typo in rev.15082