[master] ee33662a1 do not pass a NULL pointer from strerror() to vsnprintf via VSL

Poul-Henning Kamp phk at phk.freebsd.dk
Thu Nov 1 13:33:24 UTC 2018


--------
In message <20181101110711.22DFBA1900 at lists.varnish-cache.org>, Nils Goroll wri
tes:

>commit ee33662a162cbc4fcc7fb8a93d143f85b7786eae
>Author: Nils Goroll <nils.goroll at uplex.de>
>Date:   Thu Nov 1 11:45:11 2018 +0100
>
>    do not pass a NULL pointer from strerror() to vsnprintf via VSL
>    
>    (at leat on solaris) strerror() itself may fail for an out-of-memory
>    condition (because the localization code contains memory
>    allocations). In order to handle this situation, we need to save the
>    original errno because strerror() may also set errno.
>    
>    This issue exists in many more places all over the code, but in the
>    pool_breed case we likely failed pthread_create for an out-of-memory
>    condition, and in the panic handler we want to make sure that we
>    trip no follow-up panic under any circumstances.
>    
>    In general, while fixing all strerror() calls would unnecessarily
>    complicate the code, doing so should be justified for these cases.
>    
>    Fixes #2815

I suggest adding a wrapper:


	const char *
	VSOMETHING_strerror(int e)
	{
		const char *p;

		p = strerror(e);
		if (p != NULL)
			return (p)
		// XXX: try strerror_p(3) if it exists
		return ("strerror(3) returned NULL");
	}

Rather than polute all the code...

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


More information about the varnish-commit mailing list