Amos Jeffries [Wed, 9 Jan 2013 00:14:43 +0000 (17:14 -0700)]
Bug 3731: TOS setsockopt() requires int value
FreeBSD is confirmed errors on 8-bit variable size. Other BSD are
documented in a way that implies they do as well, although not at this
stage confirmed to be failing.
Linux seems to be the only confirmed system working with 8-bit size sent
to setsockopt(). So we revert this to 'int' (32-bit or 64-bit) as was
working in Squid 3.1.
Amos Jeffries [Sun, 2 Dec 2012 21:25:28 +0000 (14:25 -0700)]
Bug 3698: Add missing include to xstrerror.h
later versions were fixed as poart of trunk rev.12290 which added a lot
of errno.h includes. However all that is needed is this one to pull it
in through libcompat headers which cover all .cc.
xstrerror.h is the right place to add the include because it is the place
presenting a macro inlining the dependency.
Amos Jeffries [Fri, 30 Nov 2012 13:38:38 +0000 (06:38 -0700)]
Treat no-cache as must-revalidate in Authentication
Wrapped as a violation because this operation is off-spec.
CC:no-cache was omitted from the HTTP spec apparently on grounds that
changing its caching effects on authentication would come as a surprise.
The actual operation is safe enough to use when parameterless no-cache
is treated strictly as an alias for must-revalidate (as done by Squid now).
Amos Jeffries [Fri, 30 Nov 2012 13:34:49 +0000 (06:34 -0700)]
Fix several buffer termination bugs
* strcpy() replaced in several places with strncpy() to ensure destination
buffers are not overflowed.
* strncpy() does not nul-terminate the destination when the string being
copied in exactly fills the buffer. Ensure we have terminated strings
where it may matter.
Detected by Coverity Scan. Issues 740309, 740310, 740311, 740481, 740483
Amos Jeffries [Fri, 30 Nov 2012 13:31:52 +0000 (06:31 -0700)]
Remove MemPoolChunked::memPID
This member variable appears to have been missed when MemPool was split
into generic framework and specific Chunked implementation.
(rev:10513.1.1 aka trunk rev:10517)
The memPID and its maintenance code was moved into MemImplementingAllocator
but this definition left here un-initialized and shadowing the framework
member.
Amos Jeffries [Fri, 30 Nov 2012 13:31:18 +0000 (06:31 -0700)]
negotiate_kerberos_auth: better bounds checking
* sysconf() may return -N values on some platforms or values larger than
the hard-coded 1024 buffer size for hostname. Use sizeof() instead
since the buffer is hardcoded anyway.
* also, use return instead of exit() on the test binary to reduce
warnings from static analysis compilers.
Amos Jeffries [Fri, 30 Nov 2012 13:18:30 +0000 (06:18 -0700)]
ntlm_fake_auth: Fix nesting error
Broken macro wrapping leads to the fake authenticator sending bad
responses to Squid. This can ead to users being rejected by the fake
helper whose purpose is to accept everything.
Amos Jeffries [Thu, 29 Nov 2012 11:20:18 +0000 (04:20 -0700)]
Various memory leaks in configuration parsing
This lot are all small issues derived from allocating new memory and
assigning to a pointer already pointing at previous allocation, or
passing xstrdup() output to a caller which does not directly hold the
passed memory.
Both cases will disappear once we clean up the string handling in Squid
but for now these still need fixing to avoid leaking memory.
Detected by Coverity Scan. Issues 740430, 740432, 740439.
Amos Jeffries [Thu, 29 Nov 2012 11:17:11 +0000 (04:17 -0700)]
Fix various assertion with side effects
When compiled with high optimization and assert disabled these operations
would have disappeared. The side effects being:
* Disk I/O failure protection disabled. Allowing loops in diskd write.
* squidpurge error handling on command line parse gone. Causing segfault.
* squidpurge 'I am Alive' ticker feature cease working.
Detected by Coverity Scan. Issues 740299, 740300, 740301, 740302, 740303
Amos Jeffries [Mon, 26 Nov 2012 08:35:13 +0000 (01:35 -0700)]
digest_edirectory_auth: improved error handling
Malicious response from LDAP server can cause squid helper to crash.
Missing realm value returned from LDAP without error/missing value being
indicated in the response can lead to strcmp() using a NULL pointer.
Extremely unlikely to happen in practice, but worth fixing.
Bug 3405: ssl_crtd crashes failing to remove certificate
- Try to update the index file in all cases the database modified
rows. Currently we are using the new operator.
- The find operator in database should not modify the database. Currently
if an entry is expired, ssl_crtd removes the cert file but does not
update the index file.
- Fix a small memory leak when remove entries from database: A row object
removed from TXT_DB indexes but never released.
This patch:
* Use OPENSSL_malloc and OPENSSL_free to allocate/release memory for
TXT_DB rows. OpenSSL SDK assumes that always allocated using these
functions.
* Add code in Ssl::CertificateDb::Row destructor to correctly release
a TXT_DB row.
* Add the sq_TXT_DB_delete and sq_TXT_DB_delete_row functions which
removes a row from TXT_DB indexes.
Amos Jeffries [Tue, 6 Nov 2012 12:45:17 +0000 (05:45 -0700)]
Bug 3677: Port un-pinning logic changes from 3.3
Several design changes have been made to pinning in 3.3. One of them
added a safety check to proect close handler removal in the event that
the server connection was already closed.
This ports that protection from 3.3 and fixes at least one code path
leading to bug 3677 assertions.
Amos Jeffries [Sun, 28 Oct 2012 09:54:40 +0000 (03:54 -0600)]
Remove 'Bungled' warning on missing component directives
* Make Squid display a ERROR notice and ignore squid.conf directives
which belong to components disabled at build time instead of throwing
up 'FATAL: Bungled' message and aborting.
* Polish the 'requires X' message text for better display of cases like
'requires MS Windows' and 'requires Linux'
* Add 'requires X' message for --enable-auth, --enable-eui, and
--enable-ssl-crtd which were missing.
* Add debug 'filename' for if-none and postscriptum logging
Amos Jeffries [Sat, 20 Oct 2012 12:32:21 +0000 (06:32 -0600)]
Remove the refresh_pattern ignore-no-cache option
With the HTTP/1.1 Cache-Control:no-cache compliance upgrade this option became
obsolete. Its main use-case was to force caching of responses which contained this
control. Revalidation is now happening and no-cache objects are cached by default.
The one remaining effect of ignoring no-cache is to prevent no-cache from allowing
authenticated responses being cached. Which is the opposite of its usually expected
result and allowing that change of behaviour would be counter productive.
Amos Jeffries [Sat, 20 Oct 2012 10:07:11 +0000 (04:07 -0600)]
HTTP/1.1: Cache-Control compliance upgrade
trunk rev 11361 converted Cache-Control header from using a single mask
bitmap (shared by request and response) to separate CC header objects in
the request response. This conversion contained several regressions like
the one bug 3670 reports.
This patch:
* documents HttpStateData::cacheableReply() clarifying the overall
method action and what each individual check it doing.
* resolves several visible regressions, including bug 3670.
* extends the caching to handle the "no-cache" controls as per HTTP/1.1
(MAY store, but MUST revalidate before use).
* extends the caching for several lesser known cases of "MAY store"
exemptions handling authenticated transactions.
* removes an old hack handling Pragme:no-cache (undefined in HTTP/1.1)
One side effect of now caching transactions utilizing "no-cache" is that
hacks around Pragma:no-cache are reduced to only having any effect when
Cache-Control is absent. Reducing their performance cost. And now require
--enable-http-violations is built in since HTTP/1.1 states that
response Pragma are not defined and thus SHOULD be ignored.
Wolfgang Breyha [Thu, 18 Oct 2012 04:23:10 +0000 (22:23 -0600)]
Bug 3655: pinning failure breaks NTLM and Negotiate authentication
Some additional bits for squid-3.2 ensuring that already pinned connections
are cleaned up properly before re-pinning. Also that the pointer is not
NULL before closing when un-pinning.
Alex Rousskov [Wed, 17 Oct 2012 01:02:52 +0000 (19:02 -0600)]
Allow a ufs cache_dir entry to coexist with a shared memory cache entry
... instead of being released when it becomes idle.
The original boolean version of the StoreController::dereference() code
(r11730) was written to make sure that idle unlocked local store_table entries
are released if nobody needs them (to avoid creating inconsistencies with
shared caches that could be modified in a different process).
Then, in r11786, we realized that the original code was destroying non-shared
memory cache entries if there were no cache_dirs to vote for keeping them in
store_table. I fixed that by changing the StoreController::dereference() logic
from "remove if nobody needs it" to "remove if somebody objects to keeping
it". That solved the problem at hand, but prohibited an entry to exist in
a non-shared cache_dir and in a shared memory cache at the same time.
We now go back to the original "remove if nobody needs it" design but also
give non-shared memory cache a vote so that it can protect idle but suitable
for memory cache entries from being released if there are no cache_dirs to
vote for them.
This is a second revision of the fix. The first one (r12231) was reverted
because it did not pass tests/testRock unit tests on some platforms. The unit
tests assume that the entry slot is not locked after the entry is stored, but
the first revision of the fix allowed idle entries to remain in store_table
and, hence, their slots were locked and could not be replaced, causing
assertions. This revision allows the idle entry to be destroyed (and its slot
unlocked) if [non-shared] memory caching is disabled.
It is not clear why only some of the platforms were affected by this. Should
not memory caching be disabled everywhere during testRock (because testRock
does not set memory cache capacity and memory cache entry size limits)?
Amos Jeffries [Wed, 17 Oct 2012 00:43:57 +0000 (18:43 -0600)]
HTTP/1.1: honour Cache-Control before Pragma:no-cache
HTTPbis WG clarifications on the interaction between Cache-Control and
Pragma specify that Cache-Control may be explicitly crafted to allow
conditional caching by HTTP/1.1 caches and Pragma:no-cache supplied to
prevent caching by older HTTP/1.0 caches unable to understand the
Cache-Control properly.
Squid does obey Cache-Control. So we can deprecate Pragma to the side
cases when Cache-Control is absent entirely.
Alex Rousskov [Wed, 17 Oct 2012 00:02:26 +0000 (18:02 -0600)]
Reverted trunk r12255 changes. Provided a portable flexible arrays replacement.
Trunk r12255 made Clang compiler happy by removing flexible nonPod[] arrays.
Unfortunately, it also moved shared memory items into local memory (in some
cases uninitialized).
This change provides a Clang-friendly flexible array replacement while keeping
items in the shared memory (and using placement-new initialization). The code
may have become even less readable, but hopefully more portable.
N.B. Flexible arrays were introdiced in C99 standard, after C++ was
standardized in 1998. They are not yet in any revised C++ standard, but most
C++ compilers support them, at least for PODs.
Alex Rousskov [Sun, 14 Oct 2012 00:13:18 +0000 (18:13 -0600)]
Do not check 'reply content_length is too big' condition twice.
Saves a few CPU cycles. No visible runtime effects are expected.
The semi-duplicate check was introduced in trunk r4410 while trying to
prevent huge objects from being swapped out. It is not clear to me why
that change helped at the time (but it could have something to do with
negative content_length values and their effect on then-current size
types).
Amos Jeffries [Sat, 6 Oct 2012 02:26:32 +0000 (20:26 -0600)]
Fix website config display of default settings
The website page cfgman builder script was omitted when adding the
DEFAULT_DOC parameter and making DEFAULT / DEFAULT_IF_NONE support
multi-line values.
Amos Jeffries [Sat, 6 Oct 2012 02:18:46 +0000 (20:18 -0600)]
Small memory leak in src ACL parse
Fixes one minor memory leak when IPv6 is disabled and parsing an IPv6
address. For example the default localhost ACL ::1 value.
Caught by Valgrind:
==26647== 384 bytes in 4 blocks are definitely lost in loss record 1,132 of 1,726
==26647== at 0x4C25A28: calloc (vg_replace_malloc.c:467)
==26647== by 0x65B441: xcalloc (xalloc.cc:75)
==26647== by 0x657B99: MemPoolMalloc::allocate() (MemPoolMalloc.cc:62)
==26647== by 0x5A95B1: acl_ip_data::FactoryParse(char const*) (Ip.h:66)
==26647== by 0x5AA8BD: ACLIP::parse() (Ip.cc:523)
==26647== by 0x5E0A80: ACL::ParseAclLine(ConfigParser&, ACL**) (Acl.cc:174)
==26647== by 0x4B0C0F: parse_line(char*) (cache_cf.cc:1252)
==26647== by 0x4B2076: parseOneConfigFile(char const*, unsigned int) (cache_cf.cc:518)
==26647== by 0x4B29D0: parseConfigFile(char const*) (cache_cf.cc:558)
==26647== by 0x546B81: SquidMain(int, char**) (main.cc:1372)
==26647== by 0x547445: main (main.cc:1215)
Regression fix: Handle dstdomain duplicates and overlapping names better
Since 3.2 changes to dstdomain overlap detection teh case of duplicate
wildcards has become a fatal error needlessly.
This silently ignores all exact duplicates, even if they are wildcards.
Also, adjust the message display to always display the longer of the
domains first. Since we are dealing with sub-domains it is the most
reliable indicator of which should be removed to safely fix the detected
issue.
Alex Rousskov [Sat, 22 Sep 2012 03:12:33 +0000 (21:12 -0600)]
Do not reuse persistent connections for PUTs to avoid ERR_ZERO_SIZE_OBJECT.
A compliant proxy may retry PUTs, but Squid lacks the [rather complicated]
code required to protect the PUT request body from being nibbled during the
first try or [also tricky] code to send 100-continue expectation requiredto
delay body sending. Thus, Squid cannot safely retry some PUTs today, and
FwdState::checkRetriable() must return false for all PUTs, to avoid
bogus ERR_ZERO_SIZE_OBJECT errors (especially for clients that did not
reuse a pconn and, hence, may not be ready to handle/retry an error response).
In theory, requests with safe or idempotent methods other than PUT might have
bodies so we apply the same logic to them as well.
This reopens Squid bug #3398, undoing trunk r11859 commit which attempted
to close that bug.
Alex Rousskov [Sat, 22 Sep 2012 03:11:24 +0000 (21:11 -0600)]
Do not chunk responses carrying a Content-Range header.
When Squid forwards a response with a Content-Range header,
ClientSocketContext::socketState() detects the end of the response range(s)
and returns STREAM_*COMPLETE to ClientSocketContext::writeComplete().
The latter thinks that the writing of the response to the client must be
over and calls keepaliveNextRequest() instead of writing the last-chunk
(if any). If the to-client response was chunked, the client gets stuck
waiting for that missing last-chunk.
The multipart Range request case was already excluded from chunking (or it
would probably suffer from the same problem). With this change, no
Content-Range responses will be chunked.
N.B. Some servers send Content-Range responses to basic GET requests
without a Range header, so the problem affects more than just Range requests.
TODO: A proper fix would be to rewrite ClientSocketContext::writeComplete()
and other code so that it does not mix internal ClientStream completion with
[possibly chunk-encoded] writing completion. This should probably be done
along with fixing ClientSocketContext::socketState() and other state-checking
code to ignore to-client persistence (flags.proxy_keepalive), which is not
related to the internal ClientStream state.
Changes to interception handling in 3.2 series (namely the preference
for using ORIGINAL_DST) have increased the chances that misconfigured
network systems involving Squid will hit forwarding loops.
Two instances are currently known:
* passing forward-proxy traffic to a interception port.
* NAT performed on a separate box.
This enacts an old TODO by removing the loop detection bypass for
intercepted traffic and accelerated traffic. Now we always check for
loops regardless of how the request was received.
NOTE: accel mode was only included due to the TODO.
If problems are found there it can be re-instated.
According to CPU_SET(3) and, apparently, on some systems (e.g.,
OpenSuSE 10.3) CPU_COUNT macro expects a non-const argument. The
patch fixes build error on these systems.
Bug 3616: Retrieve client connection for ACL checks from the related HttpRequest object
This patch enable SSL client certificate ACL checks (user_cert and ca_cert)
in all cases the client connection information can retrieved from the related
HttpRequest object, eg when making peering decisions (peer_cache_access ACL).
Also fixes assertion failure caused by acl dst on transparent proxy.
Discussed under the "Supply client connection and IDENT information to
peer_cache_access ACL check" thread on squid-dev.
Amos Jeffries [Wed, 29 Aug 2012 03:36:29 +0000 (21:36 -0600)]
Regression: login=PASS send no credentials when none available.
login=PASS should act like PASSTHRU, sending no credentials header, when
no client supplied OR external ACL credentials are available.
3.2 has been found wrongly adding the username "PASS" in this case.