]> git.ipfire.org Git - thirdparty/squid.git/log
thirdparty/squid.git
19 months agoBug 3193 pt2: NTLM decoder truncating strings (#1114) v4
Amos Jeffries [Tue, 9 Aug 2022 23:34:54 +0000 (23:34 +0000)] 
Bug 3193 pt2: NTLM decoder truncating strings (#1114)

The initial bug fix overlooked large 'offset' causing integer
wrap to extract a too-short length string.

Improve debugs and checks sequence to clarify cases and ensure
that all are handled correctly.

19 months agoFix typo in manager ACL (#1113)
Amos Jeffries [Wed, 17 Aug 2022 23:32:43 +0000 (23:32 +0000)] 
Fix typo in manager ACL (#1113)

22 months agoImprove handling of Gopher responses (#1022)
Joshua Rogers [Mon, 18 Apr 2022 13:42:36 +0000 (13:42 +0000)] 
Improve handling of Gopher responses (#1022)

2 years ago4.17 (#908) SQUID_4_17
squidadm [Sun, 3 Oct 2021 17:18:09 +0000 (06:18 +1300)] 
4.17 (#908)

2 years agoWCCP: Validate packets better (#899)
Amos Jeffries [Fri, 24 Sep 2021 21:53:11 +0000 (21:53 +0000)] 
WCCP: Validate packets better (#899)

Update WCCP to support exception based error handling for
parsing and processing we are moving Squid to for protocol
handling.

Update the main WCCPv2 parsing checks to throw meaningful
exceptions when detected.

2 years ago4.16 (#852) 875/head SQUID_4_16
squidadm [Mon, 5 Jul 2021 10:09:36 +0000 (22:09 +1200)] 
4.16 (#852)

2 years agoBug 4528: ICAP transactions quit on async DNS lookups (#795)
Alex Rousskov [Fri, 21 May 2021 18:47:36 +0000 (18:47 +0000)] 
Bug 4528: ICAP transactions quit on async DNS lookups (#795)

The bug directly affected some ICAP OPTIONS transactions and indirectly
affected some ICAP REQMOD/RESPMOD transactions:

* OPTIONS: When a transaction needed to look up an IP address of the
  ICAP service, and that address was not cached by Squid, it ended
  prematurely because Adaptation::Icap::Xaction::doneAll() was unaware
  of ipcache_nbgethostbyname()'s async nature. This bug is fixed now.

* REQMOD/RESPMOD: Adaptation::Icap::ModXact masked the _direct_ effects
  of the bug: ModXact::startWriting() sets state.writing before calling
  openConnection() which schedules the DNS lookup. That "I am still
  writing" state makes ModXact::doneAll() false while a REQMOD or
  RESPMOD transaction waits for the DNS lookup.

  However, REQMOD and RESPMOD transactions that require an OPTIONS
  transaction (because the service options have never been fetched
  before or have expired) could still fail because the OPTIONS
  transaction they trigger could fail as described in the first bullet.
  For example, the first few REQMOD and RESPMOD transactions for a given
  service -- all those started before the DNS lookup completes and Squid
  caches its result -- could fail this way. With the OPTIONS now fixed,
  these REQMOD and RESPMOD transactions should work correctly.

Broken since inception (commit fb505fa).

2 years agoBug 5129 pt1: remove Lock use from HttpRequestMethod (#825)
Amos Jeffries [Mon, 17 May 2021 08:10:33 +0000 (08:10 +0000)] 
Bug 5129 pt1: remove Lock use from HttpRequestMethod (#825)

Removes the need for a custom assignment operator with a questionable
implementation, addressing compiler and static analysis warnings.

2 years agoFix --with-valgrind-debug build broken by commit 02f5357 (#822)
Alex Rousskov [Sun, 16 May 2021 22:31:30 +0000 (22:31 +0000)] 
Fix --with-valgrind-debug build broken by commit 02f5357 (#822)

    error: cbdata_htable was not declared in this scope

2 years agoBug 5128: Translation: Fix % i typo in es/ERR_FORWARDING_DENIED (#821)
Alex Rousskov [Thu, 13 May 2021 17:27:44 +0000 (17:27 +0000)] 
Bug 5128: Translation: Fix % i typo in es/ERR_FORWARDING_DENIED (#821)

    | ERROR: .../es/ERR_FORWARDING_DENIED: Unsupported error page %code
    near % i es un...

Typo added in bbeb83f.

2 years ago4.15 (#818) SQUID_4_15
squidadm [Mon, 10 May 2021 02:04:15 +0000 (14:04 +1200)] 
4.15 (#818)

3 years agoReplace cbdata::Offset hack with offsetof() (#809)
Amos Jeffries [Tue, 4 May 2021 01:39:44 +0000 (01:39 +0000)] 
Replace cbdata::Offset hack with offsetof() (#809)

Also remove unused OFFSET_OF macro.

3 years agoStop processing a response if the Store entry is gone (#806)
Alex Rousskov [Mon, 3 May 2021 21:40:14 +0000 (21:40 +0000)] 
Stop processing a response if the Store entry is gone (#806)

HttpStateData::processReply() is usually called synchronously, after
checking the Store entry status, but there are other call chains.

StoreEntry::isAccepting() adds STORE_PENDING check to the ENTRY_ABORTED
check. An accepting entry is required for writing into Store. In theory,
an entry may stop accepting new writes (without being aborted) if
FwdState or another entry co-owner writes an error response due to a
timeout or some other problem that happens while we are waiting for an
I/O callback or some such.

N.B. HTTP and FTP code cannot use StoreEntry::isAccepting() directly
because their network readers may not be the ones writing into Store --
the content may go through the adaptation layer first and that layer
might complete the store entry before the entire peer response is
received. For example, imagine an adaptation service that wants to log
the whole response containing a virus but also replaces that (large)
response with a small error reply.

3 years agoBug 5106: Broken cache manager URL parsing (#788)
Amos Jeffries [Fri, 30 Apr 2021 05:15:44 +0000 (05:15 +0000)] 
Bug 5106: Broken cache manager URL parsing (#788)

Use already parsed request-target URL in cache manager and
update CacheManager to Tokanizer based URL parse

Removing use of sscan() and regex string processing which have
proven to be problematic on many levels. Most particularly with
regards to tolerance of normally harmless garbage syntax in URLs
received.

Support for generic URI schemes is added possibly resolving some
issues reported with ftp:// URL and manager access via ftp_port
sockets.

Truly generic support for /squid-internal-mgr/ path prefix is
added, fixing some user confusion about its use on cache_object:
scheme URLs.

TODO: support for single-name parameters and URL #fragments
are left to future updates. As is refactoring the QueryParams
data storage to avoid SBuf data copying.

3 years agoFix GCC 10.2.0 build on Ubuntu Hirsute s390x (#796)
Sergio Durigan Junior [Sun, 4 Apr 2021 20:16:47 +0000 (20:16 +0000)] 
Fix GCC 10.2.0 build on Ubuntu Hirsute s390x (#796)

GCC reports
 error: free-nonheap-object: snmp_core.cc(950): snmpCreateOidFromStr

3 years agoAdd missing include (#810)
Amos Jeffries [Mon, 3 May 2021 04:09:50 +0000 (16:09 +1200)] 
Add missing include (#810)

3 years agoHandle more partial responses (#791) 807/head
Alex Rousskov [Fri, 2 Apr 2021 07:46:20 +0000 (07:46 +0000)] 
Handle more partial responses (#791)

3 years agoHandle more Range requests (#790)
Alex Rousskov [Wed, 31 Mar 2021 02:44:42 +0000 (02:44 +0000)] 
Handle more Range requests (#790)

Also removed some effectively unused code.

3 years agoBug 5112: Excessively loud chunked reply parsing error reporting (#789)
Alex Rousskov [Tue, 16 Mar 2021 17:51:05 +0000 (17:51 +0000)] 
Bug 5112: Excessively loud chunked reply parsing error reporting (#789)

Traffic parsing errors should be reported at level 2 (or below) because
Squid admins can usually do nothing about them and a noisy cache.log
hides important problems that they can and should do something about.

TODO: Detail this and similar parsing errors for %err_detail logging.

Also removed an unnecessary used-once macro.

3 years agoLimit HeaderLookupTable_t::lookup() to BadHdr and specific IDs
Alex Rousskov [Tue, 16 Mar 2021 15:45:11 +0000 (11:45 -0400)] 
Limit HeaderLookupTable_t::lookup() to BadHdr and specific IDs

3 years agoFix HttpHeaderStats definition to include hoErrorDetail (#787)
Alex Rousskov [Mon, 15 Mar 2021 14:05:05 +0000 (14:05 +0000)] 
Fix HttpHeaderStats definition to include hoErrorDetail (#787)

... when Squid is built --with-openssl.

We were "lucky" that the memory area after HttpHeaderStats was not,
apparently, used for anything important enough when HttpHeader::parse(),
indirectly called from errorInitialize() during initial Squid
configuration, was writing to it.

Detected by using AddressSanitizer.

The bug was created in commit 02259ff and cemented by commit 2673511.

3 years agoBug 5104: Memory leak in RFC 2169 response parsing (#778)
Amos Jeffries [Wed, 24 Feb 2021 00:53:21 +0000 (00:53 +0000)] 
Bug 5104: Memory leak in RFC 2169 response parsing (#778)

A temporary parsing buffer was not being released when
parsing completed.

3 years agoBug 3556: "FD ... is not an open socket" for accept() problems (#777)
Alex Rousskov [Fri, 19 Feb 2021 16:14:37 +0000 (16:14 +0000)] 
Bug 3556: "FD ... is not an open socket" for accept() problems (#777)

Many things could go wrong after Squid successfully accept(2)ed a socket
and before that socket was registered with Comm. During that window, the
socket is stored in a refcounted Connection object. When that object was
auto-destroyed on the error handling path, its attempt to auto-close the
socket would trigger level-1 BUG 3556 errors because the socket was not
yet opened from Comm point of view. This change eliminates that "already
in Connection but not yet in Comm" window.

The fixed BUG 3556 errors stalled affected clients and leaked their FDs.

TODO: Keeping that window closed should not require a human effort, but
achieving that goal probably requires significant changes. We are
investigating.

3 years agoProfiling: CPU timing implemented for MAC non-x86 (#757)
David CARLIER [Fri, 15 Jan 2021 15:41:47 +0000 (15:41 +0000)] 
Profiling: CPU timing implemented for MAC non-x86 (#757)

3 years agoSquid-to-client write_timeout triggers client_lifetime timeout (#747)
Alex Rousskov [Sun, 8 Nov 2020 17:50:03 +0000 (17:50 +0000)] 
Squid-to-client write_timeout triggers client_lifetime timeout (#747)

Since commit 5ef5e5c, a socket write timeout triggers two things:
* reporting of a write error to the socket writer (as designed/expected)
* reporting of a socket read timeout to the socket reader (unexpected).

The exact outcome probably depends on the transaction state, but one
known manifestation of this bug is the following level-1 message in
cache.log, combined with an access.log record showing a
much-shorter-than-client_lifetime transaction response time.

    WARNING: Closing client connection due to lifetime timeout

3 years agoFixed a couple of minor typos (#783)
Ambrose Li [Sun, 28 Feb 2021 16:26:22 +0000 (16:26 +0000)] 
Fixed a couple of minor typos (#783)

3 years ago4.14 (#768) SQUID_4_14
squidadm [Thu, 4 Feb 2021 22:13:34 +0000 (11:13 +1300)] 
4.14 (#768)

3 years agoBug 5073: Compile error: index was not declared in this scope (#740)
Amos Jeffries [Mon, 19 Oct 2020 01:25:50 +0000 (01:25 +0000)] 
Bug 5073: Compile error: index was not declared in this scope (#740)

Use strchr(3) instead of a legacy POSIX.1-2001 index(3) API.

Also removed the index() implementation on MS Windows as no longer used.

3 years agoSource Format Enforcement (#761)
squidadm [Sat, 30 Jan 2021 10:40:50 +0000 (23:40 +1300)] 
Source Format Enforcement (#761)

3 years agoTransactions exceeding client_lifetime are logged as _ABORTED (#748)
Alex Rousskov [Tue, 10 Nov 2020 21:42:18 +0000 (21:42 +0000)] 
Transactions exceeding client_lifetime are logged as _ABORTED (#748)

... rather than timed out (_TIMEOUT).

To record the right cause of death, we have to call terminateAll()
rather than setting logType.err.timedout directly. Otherwise, when
ConnStateData::swanSong() calls terminateAll(0), it overwrites our
direct setting.

3 years agoFix cachemgr.cgi regression in the bug 4957 fix (#741)
Štěpán Brož [Tue, 27 Oct 2020 10:29:18 +0000 (10:29 +0000)] 
Fix cachemgr.cgi regression in the bug 4957 fix (#741)

After master commit 2e29287, authenticated CGI interface users could not
use the menu links (getting HTTP 403 error). Symptoms in cache.log:

    CacheManager: unknown@...: password needed for 'menu'
    CacheManager: <username>@...: incorrect password for 'menu'

3 years agoBug 5076: WCCP Security Info incorrect (#725)
Craig Gowing [Wed, 30 Sep 2020 16:46:39 +0000 (16:46 +0000)] 
Bug 5076: WCCP Security Info incorrect (#725)

When generating and validating WCCP2 Security Info use only an
8 byte password.

3 years agoBug 5065: url_rewrite_program documentation update (#692)
Patrick Scott Best [Tue, 15 Sep 2020 17:17:11 +0000 (17:17 +0000)] 
Bug 5065: url_rewrite_program documentation update (#692)

3 years agoRestored support for non-lowercase Transfer-Encoding values (#723)
Alex Rousskov [Tue, 15 Sep 2020 04:07:43 +0000 (04:07 +0000)] 
Restored support for non-lowercase Transfer-Encoding values (#723)

... after "Improve Transfer-Encoding handling" commit f6dd87e.

Folks are reporting Chunked Transfer-Encoding values in real
traffic. HTTP requires case-insensitve treatment of codings.

3 years agoMerge pull request from GHSA-jvf6-h9gj-pmj6
Amos Jeffries [Fri, 4 Sep 2020 05:38:30 +0000 (17:38 +1200)] 
Merge pull request from GHSA-jvf6-h9gj-pmj6

* Add slash prefix to path-rootless or path-noscheme URLs

* Update src/anyp/Uri.cc

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
* restore file trailer GH auto-removes

* Remove redundant path-empty check

* Removed stale comment left behind by b2ab59a

Many things imply a leading `/` in a URI. Their enumeration is likely to
(and did) become stale, misleading the reader.

* fixup: Remind that the `src` iterator may be at its end

We are dereferencing `src` without comparing it to `\0`.
To many readers that (incorrectly) implies that we are not done iterating yet.

Also fixed branch-added comment indentation.

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
3 years ago4.13 (#718) SQUID_4_13
Amos Jeffries [Sat, 22 Aug 2020 18:37:05 +0000 (06:37 +1200)] 
4.13 (#718)

3 years agoWCCP: Fix GCC-10 -Wstringop-truncation failures (#708)
Sergio Durigan Junior [Sun, 16 Aug 2020 23:29:31 +0000 (23:29 +0000)] 
WCCP: Fix GCC-10 -Wstringop-truncation failures (#708)

I can only trigger these failures when I compile on s390x.

    In function 'char* strncpy(char*, const char*, size_t)', output
        may be truncated copying 8 bytes from a string of length 8

Signed-off-by: Sergio Durigan Junior <sergiodj@debian.org>
3 years agoImprove Transfer-Encoding handling (#702)
Amos Jeffries [Sun, 16 Aug 2020 02:21:22 +0000 (02:21 +0000)] 
Improve Transfer-Encoding handling (#702)

Reject messages containing Transfer-Encoding header with coding other
than chunked or identity. Squid does not support other codings.

For simplicity and security sake, also reject messages where
Transfer-Encoding contains unnecessary complex values that are
technically equivalent to "chunked" or "identity" (e.g., ",,chunked" or
"identity, chunked").

RFC 7230 formally deprecated and removed identity coding, but it is
still used by some agents.

3 years agoForbid obs-fold and bare CR whitespace in framing header fields (#701)
Amos Jeffries [Fri, 14 Aug 2020 15:05:31 +0000 (15:05 +0000)] 
Forbid obs-fold and bare CR whitespace in framing header fields (#701)

Header folding has been used for various attacks on HTTP proxies and
servers. RFC 7230 prohibits sending obs-fold (in any header field) and
allows the recipient to reject messages with folded headers. To reduce
the attack space, Squid now rejects messages with folded Content-Length
and Transfer-Encoding header field values. TODO: Follow RFC 7230 status
code recommendations when rejecting.

Bare CR is a CR character that is not followed by a LF character.
Similar to folding, bare CRs has been used for various attacks. HTTP
does not allow sending bare CRs in Content-Length and Transfer-Encoding
header field values. Squid now rejects messages with bare CR characters
in those framing-related field values.

When rejecting, Squid informs the admin with a level-1 WARNING such as

    obs-fold seen in framing-sensitive Content-Length: ...

3 years agoEnforce token characters for field-name (#700)
Amos Jeffries [Tue, 4 Aug 2020 04:34:32 +0000 (04:34 +0000)] 
Enforce token characters for field-name  (#700)

RFC 7230 defines field-name as a token. Request splitting and cache
poisoning attacks have used non-token characters to fool broken HTTP
agents behind or in front of Squid for years. This change should
significantly reduce that abuse.

If we discover exceptional situations that need special treatment, the
relaxed parser can allow them on a case-by-case basis (while being extra
careful about framing-related header fields), just like we already
tolerate some header whitespace (e.g., between the response header
field-name and colon).

3 years agoDo not stall while debugging a scan of an empty store_table (#699)
Eduard Bagdasaryan [Wed, 29 Jul 2020 20:51:58 +0000 (20:51 +0000)] 
Do not stall while debugging a scan of an empty store_table (#699)

Non-SMP Squid and each SMP kid allocate a store_table hash. With large
caches, some allocated store_table may have millions of buckets.

Recently we discovered that it is almost impossible to debug SMP Squid
with a large but mostly empty disk cache because the disker registration
times out while store_table is being built -- the disker process is
essentially blocked on a very long debugging loop.

The code suspends the loop every 500 entries (to take care of tasks like
kid registration), but there are no pauses when scanning millions of
empty hash buckets where every bucket prints two debug lines.

Squid now does not report empty store_table buckets explicitly. When
dealing with large caches, the debugged process may still be blocked for
a few hundred milliseconds (instead of many seconds) while scanning the
entire (mostly empty) store_table. Optimizing that should be done as a
part of the complex "store search" API refactoring.

3 years agoFix livelocking in peerDigestHandleReply (#698)
Eduard Bagdasaryan [Mon, 27 Jul 2020 15:28:31 +0000 (15:28 +0000)] 
Fix livelocking in peerDigestHandleReply (#698)

peerDigestHandleReply() was missing a premature EOF check. The existing
peerDigestFetchedEnough() cannot detect EOF because it does not have
access to receivedData.length used to indicate the EOF condition. We did
not adjust peerDigestFetchedEnough() because it is abused to check both
post-I/O state and the state after each digest processing step. The
latter invocations lack access to receivedData.length and should not
really bother with EOF anyway.

3 years agoSource Format Enforcement
SquidAdm [Mon, 10 Aug 2020 05:35:16 +0000 (05:35 +0000)] 
Source Format Enforcement

3 years agoHonor on_unsupported_protocol for intercepted https_port (#689)
Alex Rousskov [Mon, 6 Jul 2020 08:04:31 +0000 (08:04 +0000)] 
Honor on_unsupported_protocol for intercepted https_port (#689)

... when Squid discovers a non-TLS client while parsing its handshake.

For https_port traffic, ConnStateData::switchToHttps() relies on start()
to set preservingClientData_ correctly, but shouldPreserveClientData(),
called by start() to set preservingClientData_, was not preserving TLS
bytes in the https_port start() context. Typical debug messages:

    parseTlsHandshake: Got something other than TLS ... Cannot SslBump
    tunnelOnError: may have forgotten client data; send error: 40

3 years agoSslBump: Support parsing GREASEd (and future) TLS handshakes (#663)
Christos Tsantilas [Fri, 12 Jun 2020 23:32:16 +0000 (23:32 +0000)] 
SslBump: Support parsing GREASEd (and future) TLS handshakes (#663)

A peeking or staring Squid aborted TLS connections containing a GREASE
version in the supported_versions handshake extension (e.g., 0x3a3a).
Here is a sample cache.log error (debug_options ALL,1 83,2):

```
parseTlsHandshake: ... check failed: vMajor == 3
    exception location: Handshake.cc(119) ParseProtocolVersion
```

The same problem would apply to some other "unsupported" (and currently
non-existent) TLS versions (e.g., 0x0400). The growing popularity of
GREASE values exposed the bug (just like RFC 8710 was designed to do).

Squid now ignores all unsupported-by-Squid TLS versions in handshake
extensions. Squid still requires a supported TLS version for
framing-related handshake fields -- no changes there.

It is difficult to define "supported" in this context precisely because
a peeking Squid only observes the TLS handshake. Our handshake parser
may report the following versions: SSL v2.0, SSL v3.0, and TLS v1.x
(with x >= 0). This logic allows us to safely parse the handshake (no
framing errors) and continue to make version-based decisions like
disabling OpenSSL TLS v1.3 support when the agents are negotiating TLS
v1.3+ (master cd29a42). Also, access logs benefit from this "support"
going beyond TLS v1.2 even though Squid cannot bump most TLS v1.3+
handshakes.

Squid was and still is compliant with the "MUST NOT treat GREASE values
differently from any unknown value" requirement of RFC 8710.

Also added source code comments to mark other places where unsupported
(for some definition of "support") TLS values, including GREASE values
may appear.

Folks studying debugging logs (where GREASE values may appear) will
probably either recognize their easy-to-remember 0x?A?A pattern or
not really know/care about RFC 8710 and its special values.

This is a Measurement Factory project.

3 years agoBug 5051: Some collapsed revalidation responses never expire (#683)
DrDaveD [Fri, 26 Jun 2020 12:09:19 +0000 (07:09 -0500)] 
Bug 5051: Some collapsed revalidation responses never expire (#683)

* clear collapsed revalidation on a negative response

* fixup: Reduce chances of forgetting to call clearPublicKeyScope()

... in other/future sendClientUpstreamResponse() cases.

TODO:

1. Handle sendClientOldEntry() cases. We probably do not want future
   collapsed revalidation clients to accidentally collapse on the new
   entry that was rejected by this code. After all, such collapsing is
   exactly what caused bug 5051 AFAICT!

2. Consider cases where a collapsed revalidation did not reach
   handleIMSReply(). For example, imagine a client that created the
   collapsed revalidation entry and then disconnected or died. How to
   protect other clients on hitting that essentially stale entry
   forever, keeping bug 5051 alive?

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
3 years ago4.12 (#658) SQUID_4_12
squidadm [Sun, 7 Jun 2020 15:42:16 +0000 (03:42 +1200)] 
4.12 (#658)

3 years agoRevert "Fixed prohibitively slow search for new SMP shm pages (#523)"
SquidAdm [Mon, 1 Jun 2020 13:43:10 +0000 (13:43 +0000)] 
Revert "Fixed prohibitively slow search for new SMP shm pages (#523)"

This reverts commit 21200fe204f039aeaee337b79040d3560c78fb89.

3 years agoTests: Support passing a custom config.cache to test builds (#570)
Francesco Chemolli [Wed, 1 Apr 2020 21:53:47 +0000 (21:53 +0000)] 
Tests: Support passing a custom config.cache to test builds (#570)

usage:

    $ cache_file=/tmp/custom-config.cache ./test-builds.sh \
        --aggressively-use-config-cache \
        --config-cache-file=somefile.ccache
    Already bootstrapped, skipping step
    TESTING: layer-00-default

3 years agoAdd flexible RFC 3986 URI encoder (#617)
Amos Jeffries [Thu, 21 May 2020 14:42:02 +0000 (14:42 +0000)] 
Add flexible RFC 3986 URI encoder (#617)

Use AnyP::Uri namespace to self-document encoder scope and
coding type.

Use SBuf and CharacterSet for more flexible input and actions
than previous RFC 1738 encoder. Allowing callers to trivially
determine which characters are encoded.

3 years agoFix sending of unknown validation errors to cert. validator (#633)
Christos Tsantilas [Fri, 15 May 2020 04:54:54 +0000 (04:54 +0000)] 
Fix sending of unknown validation errors to cert. validator (#633)

Squid may be compiled with an OpenSSL release introducing X509
validation errors that Squid does not have the names for. Send their
integer codes.

Also sync Squid certificate verification errors with OpenSSL v1.1.1g.

This is a Measurement Factory project.

3 years agoSslBump: Disable OpenSSL TLSv1.3 support for older TLS traffic (#620)
Christos Tsantilas [Wed, 6 May 2020 07:09:50 +0000 (10:09 +0300)] 
SslBump: Disable OpenSSL TLSv1.3 support for older TLS traffic (#620)

* SslBump: Disable OpenSSL TLSv1.3 support for older TLS traffic (#588)

This change fixes stalled peeked-at during step2 connections from IE11
and FireFox v56 running on Windows 10 (at least), producing "Handshake
with SSL server failed" cache.log errors with this OpenSSL detail:

`SSL routines:ssl_choose_client_version:inappropriate fallback`

Disabling TLS v1.3 support for older TLS connections is required
because, in the affected environments, OpenSSL detects and, for some
unknown reason, blocks a "downgrade" when a server claims support for
TLS v1.3 but then accepts a TLS v1.2 connection from an older client.

This is a Measurement Factory project

* Fixed TLS selected_version parsing and debugging

The description of the expected input was given to the wrong parsing
function. This typo may have affected parsing because it told the TLS
version tokenizer that more data may be expected for the already fully
extracted extension. I believe that the lie could affect error
diagnostic when parsing malformed input, but had no effect on handling
well-formed TLS handshakes (other than less-specific debugging).

Detected by Coverity. CID 1462621: Incorrect expression (NO_EFFECT)

Broken by master commit cd29a42.

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
3 years agoCleanup: remove urlHostname hacks (#615)
Amos Jeffries [Sat, 25 Apr 2020 06:08:35 +0000 (06:08 +0000)] 
Cleanup: remove urlHostname hacks (#615)

The urlHostname() function and class it uses employ a very dirty
hack to parse a guess at the hostname portion of a URL.

AnyP::Uri objects can be used instead for better parsing of URLs
with far more accurate hostname extraction in a wider set of URI.

3 years agoFixed prohibitively slow search for new SMP shm pages (#523)
Eduard Bagdasaryan [Mon, 23 Dec 2019 08:54:53 +0000 (08:54 +0000)] 
Fixed prohibitively slow search for new SMP shm pages (#523)

The original Ipc::Mem::PageStack algorithm used an optimistic linear
search to locate the next free page. Measurements showed that, in
certain cases, that search could take seconds on busy caches, iterating
over millions of page index items and effectively stalling all workers
while showing 100% CPU utilization.

The new code uses a deterministic stack. It is still lock-free. The spin
loops around stack head pointer updates are expected to quit after at
most few iterations, even with a large number of workers. These loops do
not have ABA update problems. They are not spin locks.

3 years agoFix keyblock use for Heimdal in kerberos_ldap_group helper (#627)
huaraz [Wed, 20 May 2020 13:00:00 +0000 (13:00 +0000)] 
Fix keyblock use for Heimdal in kerberos_ldap_group helper (#627)

Heimdal uses a different keyblock structure. Symptoms:

    error: 'krb5_creds' ... has no member named 'keyblock'

3 years agoValidate Content-Length value prefix (#629)
Alex Rousskov [Wed, 13 May 2020 14:05:00 +0000 (14:05 +0000)] 
Validate Content-Length value prefix (#629)

The new code detects all invalid Content-Length prefixes but the old
code was already rejecting most invalid prefixes using strtoll(). The
newly covered (and now rejected) invalid characters are

* explicit "+" sign;
* explicit "-" sign in "-0" values;
* isspace(3) characters that are not (relaxed) OWS characters.

In most deployment environments, the last set is probably empty because
the relaxed OWS set has all the POSIX/C isspace(3) characters but the
new line, and the new line is unlikely to sneak in past other checks.

Thank you, Amit Klein <amit.klein@safebreach.com>, for elevating the
importance of this 2016 TODO (added in commit a1b9ec2).

3 years agogcc-8+ build error: undefined reference to __atomic_is_lock_free (#625)
Eduard Bagdasaryan [Tue, 12 May 2020 14:50:10 +0000 (14:50 +0000)] 
gcc-8+ build error: undefined reference to __atomic_is_lock_free (#625)

Compilers warned about AC_SEARCH_LIBS(__atomic_load_8)-generated code.
Newer, stricter compilers (e.g., gcc-8), exit with an error, resulting
in AC_SEARCH_LIBS failure when determining whether libatomic is needed.

More at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=907277#30

It is unclear whether autoconf will ever handle this case better. Let's
use a custom-made test for now. The current test refuses to build Squid
on platforms where a program using std::atomic<T>::is_lock_free() cannot
be successfully linked (either with or without libatomic) for a the
largest atomic T used by Squid (i.e. a 64 bit integer).

Linking with libatomic may be required for many reasons that we do not
fully understand, but we know that std::atomic<T>::is_lock_free() does
require linking with libatomic in some environments, even where T is an
inlineable atomic. That is why we use that as a test case.

3 years agoBug 5045: ext_edirectory_userip_acl is missing include files (#624)
Alex Rousskov [Tue, 5 May 2020 22:24:51 +0000 (22:24 +0000)] 
Bug 5045: ext_edirectory_userip_acl is missing include files (#624)

Discovered on FreeBSD v12.1 running on amd64 with clang v8.0.1.

    error: use of undeclared identifier 'AF_INET6'
    error: member access into incomplete type 'struct sockaddr_in6'
    ...

Co-Authored-By: Pavel Timofeev <timp87@gmail.com>
3 years agoFix IPFilter IPv6 detection, especially on NetBSD (#596)
sborrill [Fri, 1 May 2020 02:26:44 +0000 (02:26 +0000)] 
Fix IPFilter IPv6 detection, especially on NetBSD (#596)

Has been broken since 4eaf432.

1. acinclude/os-deps.m4 was missing sys/param.h header

2. acinclude/os-deps.m4 was incorrectly assuming that netinet/ip_nat.h
   header is always present

3. acinclude/os-deps.m4 was missing netinet/ip_nat.h header where it was
   used instead of ip_nat.h

4. src/ip/Intercept.cc assumed that AC_CHECK_MEMBERS(`struct X`)
   outputs `HAVE_X`, but it actually outputs `HAVE_STRUCT_X`.

5. acinclude/os-deps.m4: AC_CHECK_MEMBERS(`X  `) converted trailing
   whitespace into surprising trailing underscores: `HAVE_X__`

3 years agoRestore PURGE miss replies to be "404 Not Found", not "0 Init" (#586)
Christos Tsantilas [Thu, 2 Apr 2020 15:21:28 +0000 (15:21 +0000)] 
Restore PURGE miss replies to be "404 Not Found", not "0 Init" (#586)

Since commit 6956579, PURGE requests resulted in invalid HTTP responses
with zero status code when Store lacked both GET and HEAD entries with
the requested URI.

Also adjusted Http::StatusLine packing code to avoid generating similar
invalid responses in the future (and to attract developer attention to
their presence in the code logic with a BUG message).

This is a Measurement Factory project.

4 years agoBug 5030: Negative responses are never cached (#614)
DrDaveD [Wed, 6 May 2020 07:12:15 +0000 (02:12 -0500)] 
Bug 5030: Negative responses are never cached (#614)

Negative caching was blocked by checkCachable().

Since 3e98df2, Squid cached ENTRY_NEGCACHED entries in memory cache
only. Back then, storeCheckSwapable() prevented what later became
ENTRY_NEGCACHED entries from going to disk. The design was obscured by
8350fe9 that renamed storeCheckSwapable() to storeCheckCachable().

Commit 97754f5 violated that (obscured) design by adding a
checkCachable() call to StoreEntry::memoryCachable(), effectively
blocking ENTRY_NEGCACHED entries from the memory cache as well. That
call should have been added, but checkCachable() should not have denied
caching rights to ENTRY_NEGCACHED -- the corresponding check should have
been moved into StoreEntry::mayStartSwapOut().

By removing ENTRY_NEGCACHED from checkCachable(), we now allow
ENTRY_NEGCACHED entries into both memory and disk caches, subject to all
the other checks. We allow ENTRY_NEGCACHED to be cached on disk because
negative responses are fundamentally no different than positive ones:
HTTP allows caching of 4xx and 5xx responses expiring in the future.
Hopefully, the increased disk cache traffic will not be a problem.

This is master commit 91870bf backported to v4.

4 years agoBug 5041: Missing Debug::Extra breaks build on hosts with systemd (#611)
Alex Rousskov [Thu, 23 Apr 2020 11:56:35 +0000 (05:56 -0600)] 
Bug 5041: Missing Debug::Extra breaks build on hosts with systemd (#611)

* Bug 5041: Missing Debug::Extra breaks build on hosts with systemd

Master commit 6fa8c66 (i.e. Bug 5016 fix) relied on Debug::Extra added
by master commit (ccfbe8f) that was not ported to v4. The port of the
former master commit lacked the required piece of the latter commit.

The problem is invisible on hosts without a systemd package (that Squid
can find/use) and with Squids explicitly ./configured --without-systemd.

* "Minimum features" build test should be --without-systemd

* LDFLAGS were missing SYSTEMD_LIBS in builds with systemd support

Co-authored-by: Amos Jeffries <yadij@users.noreply.github.com>
4 years agoAdd missing 4.11 snapshot label (#610) SQUID_4_11
squidadm [Sun, 19 Apr 2020 13:33:22 +0000 (01:33 +1200)] 
Add missing 4.11 snapshot label (#610)

4 years ago4.11 (#609)
squidadm [Sat, 18 Apr 2020 18:46:00 +0000 (06:46 +1200)] 
4.11 (#609)

4 years agoDocs: fix version typo in wccp_address, wccp2_address directives (#595)
tomofumi-yoshida [Sat, 11 Apr 2020 01:00:00 +0000 (01:00 +0000)] 
Docs: fix version typo in wccp_address, wccp2_address directives (#595)

The descriptions of wccp_address and wccp2_address directives were
reversed.

4 years agoBug 5036: capital 'L's in logs when daemon queue overflows (#576)
DrDaveD [Thu, 2 Apr 2020 17:58:10 +0000 (17:58 +0000)] 
Bug 5036: capital 'L's in logs when daemon queue overflows (#576)

Varying number of capital 'L's have been observed in access logs
written by the daemon module.  The 'L's corresponded with the
cache log message:

  "queue is too large; some log messages have been lost."

This was caused by the fact that the 'L' command byte was
buffered even when the queue was too large to accept messages.

Deferring buffering the command byte until just before the
message itself is buffered.

4 years agoFix auth digest refcount integer overflow (#585)
desbma-s1n [Thu, 2 Apr 2020 11:16:45 +0000 (11:16 +0000)] 
Fix auth digest refcount integer overflow (#585)

This fixes a possible overflow of the nonce reference counter in the
digest authentication scheme, found by security researchers
@synacktiv.

It changes `references` to be an 64 bits unsigned integer. This makes
overflowing the counter impossible in practice.

4 years agoFtpGateway.cc: fix build on gcc-10 [-Werror=class-memaccess] (#573)
Francesco Chemolli [Sat, 21 Mar 2020 22:18:43 +0000 (22:18 +0000)] 
FtpGateway.cc: fix build on gcc-10 [-Werror=class-memaccess] (#573)

Since a1c06c7, tokens initialization is done by FtpLineToken
constructor, and g++-10 complains about memsetting a nontrivial object:

    clearing an object of non-trivial type [-Werror=class-memaccess]

4 years agoESI: convert parse exceptions into 500 status response (#411)
Amos Jeffries [Mon, 20 May 2019 11:23:13 +0000 (11:23 +0000)] 
ESI: convert parse exceptions into 500 status response  (#411)

Produce a valid HTTP 500 status reply and continue operations when
ESI parser throws an exception. This will prevent incomplete ESI
responses reaching clients on server errors. Such responses might
have been cacheable and thus corrupted, albeit corrupted consistently
and at source by the reverse-proxy delivering them.

ESI: throw on large stack recursions (#408)

This reduces the impact on concurrent clients to only those
accessing the malformed resource.

Depending on what type of recursion is being performed the
resource may appear to the client with missing segments, or
not at all.

4 years agoBug 5022: Reconfigure kills Coordinator in SMP+ufs configurations (#556)
DrDaveD [Fri, 21 Feb 2020 05:12:04 +0000 (05:12 +0000)] 
Bug 5022: Reconfigure kills Coordinator in SMP+ufs configurations (#556)

In these unsupported SMP+ufs configurations, depending on the deployment
specifics, the Coordinator process could exit due to swap state file
opening errors:

    kid11| FATAL: UFSSwapDir::openLog: Failed to open swap log.

4 years agoRemove pointer from the input of Digest nonce hashes (#549)
squidcontrib [Wed, 29 Jan 2020 06:10:04 +0000 (06:10 +0000)] 
Remove pointer from the input of Digest nonce hashes (#549)

This is a follow-up to #491 (b20ce97), which hashed what was previously
revealed as plaintext. Removing the pointer from the input to the hash
removes the possibility that someone could recover a pointer by
reversing a hash. Having the pointer as input was not adding anything:
Squid remembers all outstanding nonces, so it really only requires
uniqueness, which is already guaranteed by the
authenticateDigestNonceFindNonce loop.

4 years agokerberos_ldap_group: fix encryption type for cross realm check (#542)
huaraz [Sat, 25 Jan 2020 03:36:49 +0000 (03:36 +0000)] 
kerberos_ldap_group: fix encryption type for cross realm check (#542)

Newer setups require AESxxx encryption but old Crossrealm
tickets are still using RC4. Remove the use of the cached client
ticket encryption type and use the configured default list
(which must include AESxxx and RC4).

4 years agoBug 5016: systemd thinks Squid is ready before Squid listens (#539)
Marcos Mello [Thu, 23 Jan 2020 12:07:40 +0000 (12:07 +0000)] 
Bug 5016: systemd thinks Squid is ready before Squid listens (#539)

Use systemd API to send start-up completion notification if built
with libsystemd support. New configure option --with-systemd
can be used to force enable or disable the feature (default:
auto-detect on Linux platforms).

4 years agoFix string truncation in getnameinfo() (#462)
Amos Jeffries [Sun, 5 Jan 2020 13:29:29 +0000 (13:29 +0000)] 
Fix string truncation in getnameinfo() (#462)

strncpy can leave strings unterminated. Use xstrncpy instead
of relying on callers to terminate their buffers.

4 years agopeer selection procedure for pinned connection should return the
Christos Tsantilas [Thu, 28 Nov 2019 10:00:45 +0000 (12:00 +0200)] 
peer selection procedure for pinned connection  should return the
CachePeer object if any.

This is required by caller to check if the pinned connection is still
valid.

4 years agoBug 4864: !Comm::MonitorsRead assertion in maybeReadVirginBody() (#351)
Christos Tsantilas [Wed, 27 Nov 2019 16:20:27 +0000 (18:20 +0200)] 
Bug 4864: !Comm::MonitorsRead assertion in maybeReadVirginBody() (#351)

This assertion is probably triggered when Squid retries/reforwards
server-first or step2+ bumped connections (after they fail).
Retrying/reforwarding such pinned connections is wrong because the
corresponding client-to-Squid TLS connection was negotiated based on the
now-failed Squid-to-server TLS connection, and there is no mechanism to
ensure that the new Squid-to-server TLS connection will have exactly the
same properties. Squid should forward the error to client instead.

Also fixed peer selection code that could return more than one PINNED
paths with only the first path having the destination of the actual
pinned connection.

This is a Measurement Factory project

This is a limited equivalent to master branch commit 3dde9e52

4 years agoSupply ALE to request_header_add/reply_header_add (#564)
Christos Tsantilas [Thu, 12 Mar 2020 17:21:46 +0000 (19:21 +0200)] 
Supply ALE to request_header_add/reply_header_add (#564)

Supply ALE to request_header_add and reply_header_add ACLs that need it
(e.g., external, annotate_client, and annotate_transaction ACLs). Fixes
"ACL is used in context without an ALE state" errors when external ACLs
are used in the same context (other ACLs do not yet properly disclose
that they need ALE).

Also provides HTTP reply to reply_header_add ACLs.

This is a Measurement Factory project.

4 years ago4.10 (#547) SQUID_4_10
Amos Jeffries [Mon, 20 Jan 2020 07:03:16 +0000 (20:03 +1300)] 
4.10 (#547)

4 years agoPrep for v4.10 and v5.0.1 (#538)
Amos Jeffries [Tue, 14 Jan 2020 03:56:20 +0000 (03:56 +0000)] 
Prep for v4.10 and v5.0.1 (#538)

4 years agoSource Format Enforcement
SquidAdm [Thu, 16 Jan 2020 02:16:28 +0000 (02:16 +0000)] 
Source Format Enforcement

4 years agoBug 5007: Docs: Fix max_filedescriptors description (#529)
DrDaveD [Wed, 1 Jan 2020 22:56:34 +0000 (22:56 +0000)] 
Bug 5007: Docs: Fix max_filedescriptors description (#529)

max_filedescriptors can also be used to _raise_  the number of
descriptors (up to the OS hard limit).

4 years agoBug 4735: Truncated chunked responses cached as whole (#528)
DrDaveD [Mon, 30 Dec 2019 20:43:33 +0000 (20:43 +0000)] 
Bug 4735: Truncated chunked responses cached as whole (#528)

Mark responses received without the last chunk as responses that have
bad (and, hence, unknown) message body length (i.e. ENTRY_BAD_LENGTH).
If they were being cached, such responses will be released and will stop
being shareable.

4 years agoFix server_cert_fingerprint on cert validator-reported errors (#522)
Christos Tsantilas [Wed, 25 Dec 2019 17:21:30 +0000 (17:21 +0000)] 
Fix server_cert_fingerprint on cert validator-reported errors (#522)

The server_cert_fingerprint ACL mismatched when sslproxy_cert_error
directive was applied to validation errors reported by the certificate
validator because the ACL could not find the server certificate.

This is a Measurement Factory project.

4 years agoFix request URL generation in reverse proxy configurations (#519)
Guido Vranken [Thu, 12 Dec 2019 03:27:40 +0000 (03:27 +0000)] 
Fix request URL generation in reverse proxy configurations (#519)

4 years agoFix FTP buffers handling (#521)
Christos Tsantilas [Fri, 20 Dec 2019 07:29:58 +0000 (07:29 +0000)] 
Fix FTP buffers handling (#521)

Fix the parsing of the received listing from FTP services.
Also relaxed size/filename grammar used for DOS listings: Tolerate
multiple spaces between the size and the filename.

This is a Measurement Factory project

4 years agoFix shared memory size calculation on 64-bit systems (#520)
Eduard Bagdasaryan [Tue, 17 Dec 2019 15:01:05 +0000 (15:01 +0000)] 
Fix shared memory size calculation on 64-bit systems (#520)

Since commit 2253ee0, the wrong type (uint32 instead of size_t) was used
to calculate the PagePool::theLevels size. theLevels memory (positioned
by different and correct code) did not overlap with the raw pages
buffer, but the raw pages buffer could, in some cases, be 32 bits short,
placing the last 4 bytes of the last page outside of allocated memory.

In practice, shared memory allocations are page-aligned, and the
difference in 4 bytes was probably compensated by the extra allocated
bytes in most (or perhaps even all) cases.

4 years agoBug 5008: SIGBUS in PagePool::level() with custom rock slot size (#515)
jijiwawa [Sat, 23 Nov 2019 10:24:41 +0000 (10:24 +0000)] 
Bug 5008: SIGBUS in PagePool::level() with custom rock slot size (#515)

SMP Squids were crashing on arm64 due to incorrect memory alignment of
Ipc::Mem::PagePool::theLevels array. The relative position of the array
depends on the number of workers and the number of pages (influenced by
the cache capacity and slot size), so some configurations worked OK.

We have to manually align manually positioned fields inside shared
memory segments. Thankfully, C++11 provides alignment-computing APIs.

4 years agoBug 5009: Build failure with older clang libc++ (#514)
Alex Rousskov [Sat, 23 Nov 2019 09:18:24 +0000 (09:18 +0000)] 
Bug 5009: Build failure with older clang libc++ (#514)

Older clang libc++ implementations correctly reject implicit usage of an
explicit (in C++11) std::map copy constructor with "chosen constructor
is explicit in copy-initialization" errors. The same code becomes legal
in C++14[1], so newer libc++ implementation allow implicit usage (even
in C++11), but there is no need for copy-initialization here at all.
Evidently, libstdc++ has never declared constructors explicit.

The bug was seen with Apple clang in Xcode 5.1.1 (roughly upstream clang
3.4) and Xcode 6.2 (roughly upstream clang 3.5), both using libc++.

[1] http://cplusplus.github.io/LWG/lwg-defects.html#2193

4 years agoDocs: mention --foreground in squid -z man page (#508)
Marcos Mello [Sat, 23 Nov 2019 06:25:47 +0000 (06:25 +0000)] 
Docs: mention --foreground in squid -z man page (#508)

4 years agoext_lm_group_acl: Improved username handling (#512)
aaron-costello [Fri, 22 Nov 2019 02:44:29 +0000 (02:44 +0000)] 
ext_lm_group_acl: Improved username handling (#512)

4 years agoFix Security::ServerOptions copy-constructor (#513)
Amos Jeffries [Wed, 20 Nov 2019 05:20:04 +0000 (05:20 +0000)] 
Fix Security::ServerOptions copy-constructor (#513)

clientCaStack uses a std::unique_ptr which cannot be copied.

4 years agoFix detection of sys/sysctl.h detection (#511)
Amos Jeffries [Mon, 18 Nov 2019 12:06:56 +0000 (01:06 +1300)] 
Fix detection of sys/sysctl.h detection (#511)

Make sure we test the EUI specific headers using same flags
chosen for final build operations. This should make the
test detect the header as unavailable if the user options
would make the compiler #warning be a fatal error later.

4 years ago4.9 (#507) 524/head 526/head SQUID_4_9
squidadm [Tue, 5 Nov 2019 19:14:40 +0000 (08:14 +1300)] 
4.9 (#507)

4 years agocachemgr.cgi: Add validation for hostname parameter (#504)
aaron-costello [Sun, 3 Nov 2019 16:22:22 +0000 (16:22 +0000)] 
cachemgr.cgi: Add validation for hostname parameter (#504)

Prevention of HTML/invalid chars in host param

4 years agoSource Format Enforcement
SquidAdm [Sat, 2 Nov 2019 12:57:07 +0000 (12:57 +0000)] 
Source Format Enforcement

4 years agoFix expiration of self-signed generated certs to be 3 years (#501)
James DeFelice [Mon, 28 Oct 2019 10:53:51 +0000 (10:53 +0000)] 
Fix expiration of self-signed generated certs to be 3 years (#501)

Generated self-signed certificates lifetime was incorrectly set to
356*3 days, which is approximately 27 days shorter than 3 years.

The fixed problem does not affect Squids using "sslproxy_cert_adapt
setValidAfter" and Squids using a configured signing CA certificate.

4 years agoHash Digest noncedata (#491)
squidcontrib [Sun, 20 Oct 2019 18:59:08 +0000 (18:59 +0000)] 
Hash Digest noncedata (#491)

These commits together
1. Hash the noncedata for Digest nonces before encoding,
   to match the documentation.
2. Encode Digest nonces using hex, rather than base64.

4 years agosmblib: Improve SMB server name maintenance (#494)
aaron-costello [Fri, 18 Oct 2019 23:03:27 +0000 (23:03 +0000)] 
smblib: Improve SMB server name maintenance (#494)

4 years agoFix rock disk entry contamination related to aborted swapouts (#444)
Eduard Bagdasaryan [Wed, 7 Aug 2019 12:04:30 +0000 (12:04 +0000)] 
Fix rock disk entry contamination related to aborted swapouts (#444)

Also probably fixed hit response corruption related to aborted rock
swapins.

The following disk entry contamination sequence was observed in detailed
cache logs during high-load Polygraph tests. Some of the observed
level-1 errors matched those in real-world deployments.

1. Worker A schedules AX – a request to write a piece of entry A to disk
   slot X. The disker is busy writing and reading other slots for worker
   A and other workers so AX stays in the A-to-Disker queue for a while.
2. Entry A aborts swapout (for any reason, including network errors
   while receiving the being-stored response). Squid makes disk slot X
   available for other entries to use. AX stays queued.
3. Another worker B picks up disk slot X (from the shared free disk slot
   pool) and schedules BX, a request to write a piece of entry B to disk
   slot X. BX gets queued in an B-to-Disker queue. AX stays queued.
4. The disker satisfies write request BX. Disk slot X contains entry B
   contents now. AX stays queued.
5. The disker satisfies write request AX. Disk slot X is a part of entry
   B slot chain but contains former entry A contents now! HTTP requests
   for entry B now read entry A leftovers from disk and complain about
   metadata mismatches (at best) or get wrong response contents (at
   worst).

To prevent premature disk slot reuse, we now keep disk slots reserved
while they are in the disk queue, even if the corresponding cache entry
is long gone: Individual disk write requests now "own" the slot they are
writing. The Rock::IoState object owns reserved but not yet used slots
so that they can be freed when the object is gone. The disk entry owns
the (successfully written) slots added to its chain in the map.

The new slot ownership scheme required changes in what metadata the
writing code has to maintain. For example, we now keep the address of
the previous slot in the entry chain so that we can update its .next
field after a successful disk write. Also, the old code detecting
dropped write requests could no longer rely on the now-empty .next field
in the previous map entry. The rewritten code numbers I/O transactions
so that out-of-order replies can be detected without using the map.

I tried to simplify the metadata maintenance code by shortening
reservation lifetimes and using just-in-time [first] slot reservations.
The new code may also leak fewer slots when facing C++ exceptions.

As for reading, I realized that we had no protection from dropped rock
read requests. If the first read request is dropped, the metadata
decoding would probably fail but if subsequent reads are skipped, the
client may be fed with data that is missing those skipped blocks. I did
not try to reproduce these problems, but they are now fixed using the
same I/O transaction numbering mechanism that the writing code now uses.
Negative length checks in store_client.cc treat dropped reads as errors.

I also removed commented out "partial writing" code because IoState
class member changes should expose any dangerous merge problems.

4 years agoFix URN response handling (#472)
Eduard Bagdasaryan [Sun, 15 Sep 2019 15:32:30 +0000 (15:32 +0000)] 
Fix URN response handling (#472)

urnHandleReply() may be called several times while copying the entry
from the store. Each time it must use the buffer length that is left
(from the previous call).

Also do not abandon a urn entry, still having clients attached.

Also allow urnHandleReply() to produce a reply if it receives a
zero-sized buffer. This may happen after the entry has been fully
stored.

CID 1453857: Error handling issues (UNCAUGHT_EXCEPT)

Due to various Store deficiencies, storeUnregister() might call swapout
code which Broadcast()s and throws Ipc::OneToOneUniQueue::ItemTooLarge.