From owner-freebsd-stable@FreeBSD.ORG Sun Feb 9 19:57:18 2014 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 95A5251B; Sun, 9 Feb 2014 19:57:18 +0000 (UTC) Received: from tensor.andric.com (unknown [IPv6:2001:7b8:3a7:1:2d0:b7ff:fea0:8c26]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1CD7911A0; Sun, 9 Feb 2014 19:57:18 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7::20a4:db0:4ac7:1cb7] (unknown [IPv6:2001:7b8:3a7:0:20a4:db0:4ac7:1cb7]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 01F7F5C45; Sun, 9 Feb 2014 20:57:09 +0100 (CET) Subject: Re: Squid aufs crashes under 10.0 Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) Content-Type: multipart/signed; boundary="Apple-Mail=_3C69EC2F-0210-4093-9A87-17EC5854F226"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Pgp-Agent: GPGMail 2.1 (6062eb4) From: Dimitry Andric In-Reply-To: <1391973419.88145.103.camel@btw.pki2.com> Date: Sun, 9 Feb 2014 20:56:52 +0100 Message-Id: <0760EB34-0EE7-4519-AF2F-63C0FDC4D8C5@FreeBSD.org> References: <92705E1C-E06E-411D-B88C-5A1AA096E2BD@FreeBSD.org> <1391973419.88145.103.camel@btw.pki2.com> To: Dennis Glatting X-Mailer: Apple Mail (2.1827) Cc: Pavel Timofeev , freebsd-stable stable , ports-list freebsd X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Feb 2014 19:57:18 -0000 --Apple-Mail=_3C69EC2F-0210-4093-9A87-17EC5854F226 Content-Type: multipart/mixed; boundary="Apple-Mail=_03EC8C9A-50D4-4325-AFB5-44939AB8EBDC" --Apple-Mail=_03EC8C9A-50D4-4325-AFB5-44939AB8EBDC Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=iso-8859-1 On 09 Feb 2014, at 20:16, Dennis Glatting wrote: > On Sun, 2014-02-09 at 19:37 +0100, Dimitry Andric wrote: ... >> Very bad coding practice, obviously. It should call Find() first, and >> if that returns NULL, it should abort in some sort of controlled way. >> > > Found that too but not the reason why: > > (lldb) run -d -z -F -f /root/squid.conf > Process 23598 launched: './src/squid' (x86_64) > Find(): Mmapped > Find(): IpcIo > Find(): DiskDaemon > Find(): Blocking > Find(): AIO > Returning NULL > > There's a lot of faulty (i.e., a lack thereof) checking in Squid. For > example, I replaced strlen() with a custom version that first checks for > NULL and returns 0 if that is the case (strlen() was often called by > std::cstring::c_str() that was not yet initialized). That small code > fragment resolved a lot of SEGVs. There are a bunch of places where they use std::ostream::operator<< to output e.g. configuration strings to the debug stream, for example in uniqueHostname(), in src/tools.cc: const char * uniqueHostname(void) { debugs(21, 3, HERE << " Config: '" << Config.uniqueHostname << "'"); return Config.uniqueHostname ? Config.uniqueHostname : getMyHostname(); } The problem case is when Config.uniqueHostname is NULL: this gets converted into a std::string first (which is _undefined behavior_), then it gets streamed to the debug stream. However, there is a difference between libstdc++ and libc++ here: the former silently accepts NULL arguments passed to the std::string constructor, creating a sort of "empty" string for you, which seems to work as normal. The latter just stores your NULL pointer, and if you actually try to do anything with it, the program will crash. To fix at least two places where this is done, drop the attached patches in www/squid33/files. -Dimitry --Apple-Mail=_03EC8C9A-50D4-4325-AFB5-44939AB8EBDC Content-Disposition: attachment; filename=patch-src-acl-Acl.cc Content-Type: application/octet-stream; name="patch-src-acl-Acl.cc" Content-Transfer-Encoding: 7bit --- src/acl/Acl.cc.orig 2013-11-30 14:55:13.000000000 +0100 +++ src/acl/Acl.cc 2014-02-09 20:17:03.000000000 +0100 @@ -361,7 +361,7 @@ ACL::~ACL() { - debugs(28, 3, "ACL::~ACL: '" << cfgline << "'"); + debugs(28, 3, "ACL::~ACL: '" << (cfgline ? cfgline : "") << "'"); safe_free(cfgline); } --Apple-Mail=_03EC8C9A-50D4-4325-AFB5-44939AB8EBDC Content-Disposition: attachment; filename=patch-src-tools.cc Content-Type: application/octet-stream; name="patch-src-tools.cc" Content-Transfer-Encoding: 7bit --- src/tools.cc.orig 2013-11-30 14:55:13.000000000 +0100 +++ src/tools.cc 2014-02-09 20:05:29.000000000 +0100 @@ -582,7 +582,7 @@ const char * uniqueHostname(void) { - debugs(21, 3, HERE << " Config: '" << Config.uniqueHostname << "'"); + debugs(21, 3, HERE << " Config: '" << (Config.uniqueHostname ? Config.uniqueHostname : "") << "'"); return Config.uniqueHostname ? Config.uniqueHostname : getMyHostname(); } --Apple-Mail=_03EC8C9A-50D4-4325-AFB5-44939AB8EBDC Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=iso-8859-1 --Apple-Mail=_03EC8C9A-50D4-4325-AFB5-44939AB8EBDC-- --Apple-Mail=_3C69EC2F-0210-4093-9A87-17EC5854F226 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iEYEARECAAYFAlL33YwACgkQsF6jCi4glqOy5gCfVe3+/0nVEa1mgzGlkKlMvHvS akkAoMKMROPX0EQTo0aFMt0gkQM2Jrsj =rnde -----END PGP SIGNATURE----- --Apple-Mail=_3C69EC2F-0210-4093-9A87-17EC5854F226--