apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Hay" <Steve...@planit.com>
Subject [PATCH] Fix VS2010 release builds on Vista/2008/Win7
Date Wed, 09 Feb 2011 16:28:19 GMT
See http://marc.info/?t=129681675100001&r=1&w=2 for background on this
patch.

In brief, I have found that the environment reprocessing done by APR
leaves _environ in a state such that the next call to putenv() which
replaces an existing environment variable can cause the program to
crash. The crash only comes when everything is built in release mode
with VS2010 and run on Vista, Server 2008 or Windows 7, but it does
happen every time in those cases.

Looking at the CRT source code, _environ is initialized in stdenvp.c by
mallocing an array of char* pointers and then individually mallocing
each of the environment variable strings to be pointed to by those
pointers. When putenv() is called to replace an existing environment
variable it first frees the existing malloced string, and it is that
free which crashes after APR has reprocessed the environment.

The current APR environment reprocessing works by mallocing an array of
char* pointers and then mallocing one single block of memory for the
whole array of strings which the pointers point into, so it is easy to
see how a subsequent free on one of those strings could fail, although
it isn't clear why it only crashes in release mode builds on certain
OSes or why earlier versions of the compiler didn't exhibit the same
crashing behaviour.

However, the attached patch modifies the APR environment reprocessing to
malloc each environment string individually, just like stdenvp.c did
originally, and this makes the crashes go away.

I have verified that the attached test.cpp program (which contains the
relevant functions from the APR code, modified as per my patch, with
only minor changes) runs in both release mode and debug mode builds,
using each of VC98, VS2005, VS2008 and VS2010 on both XP and Server
2008.

And I have verified that Apache HTTPd 2.2.17 + my patch / Perl 5.12.2 /
mod_perl 2.0.4 also runs in release mode builds, using each of VS2005,
VS2008 and VS2010 (I patched Perl 5.12.2 for VS2010 support as per
relevant changes in 5.13.9 for the VS2010 build) on both XP and Server
2008. (HTTPd 2.2.17 didn't build using VC98.) Note that this
HTTPd/Perl/mod_perl combination originally crashed on Server 2008 (on a
putenv() call done by Perl), which is how I originally came across this
problem.

The patch applies to the HTTPd Win32 source code zip file
(httpd-2.2.17-win32-src.zip). Please let me know if you'd rather I
supplied a patch against the plain APR sources.

Steve

Mime
View raw message