Here's what I found:
If the headers were not found and or inherited somewhere up the chain,
then ScaWriteHttpHeader allocated a single NULL WCHAR for pwzHeaders.
This introduced two issues:
1) The assertion in MultiSzFindSubstring
2) The fact that a properly terminated MULTI_SZ should have two
terminating NULL characters; MultiSzLen ended up reading past the end of
pwzHeaders.
Also, mr.pbMDData was never freed if the header was never found.
Attached is a patch; it also include a change I made to the header
handling in general that also affects a couple of lines in scaweb.cpp
and scavdir.cpp. Patch is against WiX 3.0.4923.
Thanks,
Thomas S. Trias
Senior Developer
Artizan Internet Services
http://www.artizan.com/
-------- Original Message --------
Subject: Assertion Adding IIS Headers
From: Thomas S. Trias <[email protected]>
To: Windows Installer XML toolset developer mailing list
<[email protected]>
Date: 2/13/2009 12:10 PM
This may be related to my recent reinstall of IIS, instead of anything
that changed between 3.0.4624 and 3.0.4923, but I am now getting a
failed assertion in strutil.cpp in MultiSzFindSubstring at line 1210.
I am going to debug further, but I was wondering why it throws an
assertion for an empty MULTI_SZ:
Assert(pwzMultiSz && *pwzMultiSz && pwzSubstring && *pwzSubstring);
If the MULTI_SZ is empty, *pwzMultiSz will be false. Is this an
invalid situation?
Thanks,
Base folder: .\src\ca\serverca\scasched
--- scahttpheader.cpp 2009-02-02 16:34:48.000000000 -0600
+++ scahttpheader.cpp 2009-02-13 15:24:26.000000000 -0600
@@ -160,13 +160,13 @@
return hr;
}
HRESULT ScaWriteHttpHeader(
__in IMSAdminBase* piMetabase,
- __in int iParentType,
+// __in int iParentType,
__in LPCWSTR wzRoot,
__in SCA_HTTP_HEADER* pshhList
)
{
Assert(piMetabase && pshhList);
@@ -190,12 +190,16 @@
mr.dwMDAttributes = METADATA_INHERIT;
mr.dwMDUserType = IIS_MD_UT_SERVER;
mr.dwMDDataType = ALL_METADATA;
mr.dwMDDataLen = cchData = 0;
mr.pbMDData = NULL;
+ // Either this search was wrong for a web site (since the path did not
include /Root),
+ // or the old call to ScaWriteMetabaseValue below for hhptWeb ==
iParentType was wrong.
+ // Better design is to pass /Root from the call in scaweb.cpp - that
eliminates the
+ // parent type check.
hr = MetaGetValue(piMetabase, METADATA_MASTER_ROOT_HANDLE, wzRoot, &mr);
if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr ||
MD_ERROR_DATA_NOT_FOUND == hr)
{
//
// If we don't have any HTTP Headers already, move up to get the
parent headers.
// TODO: Make it configurable to not inherit HTTP Headers
@@ -227,40 +231,37 @@
}
ExitOnFailure1(hr, "Failed to find search for HTTP headers for web
root: %S while walking up the tree", wzRoot);
if (S_OK == hr)
{
pwzHeaders = reinterpret_cast<LPWSTR>(mr.pbMDData);
+ mr.pbMDData = NULL;
break;
}
}
}
else
{
pwzHeaders = reinterpret_cast<LPWSTR>(mr.pbMDData);
+ mr.pbMDData = NULL;
}
ExitOnFailure1(hr, "Failed while searching for default HTTP headers to
start with for web root: %S", wzRoot);
-
- if (!pwzHeaders)
- {
- hr = StrAlloc(&pwzHeaders, 1);
- ExitOnFailure(hr, "Failed to allocate empty string for headers.");
- }
// Loop through the HTTP headers
for (SCA_HTTP_HEADER* pshh = pshhList; pshh; pshh = pshh->pshhNext)
{
fOldValueFound = FALSE; // assume a HTTP Header match will not be found
hr = StrAllocFormatted(&pwzNewHeader, L"%s: ", pshh->wzName);
ExitOnFailure(hr, "Failed to allocate header name");
// Try to find a matching header already in the list
do
{
- hr = MultiSzFindSubstring(pwzHeaders, pwzNewHeader,
&dwFoundHeaderIndex, &wzFoundHeader);
+ // The check of pwzHeaders gets around an assertion in
MultiSzFindSubstring; if there is no current value, then we aren't going to
find it
+ hr = pwzHeaders ? MultiSzFindSubstring(pwzHeaders, pwzNewHeader,
&dwFoundHeaderIndex, &wzFoundHeader) : S_FALSE;
ExitOnFailure(hr, "Failed while searching for existing HTTP
header.");
// If there was a substring HTTP header match, make sure the match
was at the beginning
// of the string because that is the HTTP header name.
if (S_OK == hr)
{
@@ -283,30 +284,34 @@
{
hr = MultiSzReplaceString(&pwzHeaders, dwFoundHeaderIndex,
pwzNewHeader);
ExitOnFailure(hr, "Failed to replace old HTTP header with new HTTP
header");
}
else
{
+ // Note that MultiSzPrepend handles the case where pwzHeaders is
NULL properly
hr = MultiSzPrepend(&pwzHeaders, NULL, pwzNewHeader);
ExitOnFailure(hr, "Failed to prepend new HTTP header");
}
}
// now write the HttpCustom to the metabase
- if (hhptWeb == iParentType)
- {
- hr = ScaWriteMetabaseValue(piMetabase, wzRoot, L"/Root",
MD_HTTP_CUSTOM, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, pwzHeaders);
- ExitOnFailure(hr, "Failed to write HTTP Header to web site.");
- }
- else
- {
- hr = ScaWriteMetabaseValue(piMetabase, wzRoot, NULL, MD_HTTP_CUSTOM,
METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, pwzHeaders);
- ExitOnFailure(hr, "Failed to write HTTP Headers to VDir.");
- }
+// if (hhptWeb == iParentType)
+// {
+// hr = ScaWriteMetabaseValue(piMetabase, wzRoot, L"/Root",
MD_HTTP_CUSTOM, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, pwzHeaders);
+// ExitOnFailure(hr, "Failed to write HTTP Header to web site.");
+// }
+// else
+// {
+// hr = ScaWriteMetabaseValue(piMetabase, wzRoot, NULL, MD_HTTP_CUSTOM,
METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, pwzHeaders);
+// ExitOnFailure(hr, "Failed to write HTTP Headers to VDir.");
+// }
+ hr = ScaWriteMetabaseValue(piMetabase, wzRoot, NULL, MD_HTTP_CUSTOM,
METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, pwzHeaders);
+ ExitOnFailure1(hr, "Failed to write HTTP Headers to web root: %s",
wzRoot);
LExit:
+ ReleaseNullStr(mr.pbMDData);
ReleaseNullStr(pwzNewHeader);
ReleaseNullStr(pwzHeaders);
ReleaseNullStr(pwzSearchKey);
return hr;
}
--- scahttpheader.h 2009-02-02 16:34:48.000000000 -0600
+++ scahttpheader.h 2009-02-06 17:06:16.000000000 -0600
@@ -47,10 +47,10 @@
__in LPCWSTR wzParentValue,
__in SCA_HTTP_HEADER** ppshhList,
__out SCA_HTTP_HEADER** ppshhOut
);
HRESULT ScaWriteHttpHeader(
__in IMSAdminBase* piMetabase,
- int iParentType,
+// int iParentType,
LPCWSTR wzRoot,
SCA_HTTP_HEADER* pshhList
);
--- scavdir.cpp 2009-02-02 16:34:49.000000000 -0600
+++ scavdir.cpp 2009-02-06 17:06:16.000000000 -0600
@@ -223,13 +223,14 @@
hr = ScaWriteMimeMap(piMetabase, psvd->wzVDirRoot, psvd->psmm);
ExitOnFailure(hr, "Failed to write mimemap for VirtualDir");
}
if (psvd->pshh)
{
- hr = ScaWriteHttpHeader(piMetabase, hhptVDir,
psvd->wzVDirRoot, psvd->pshh);
+// hr = ScaWriteHttpHeader(piMetabase, hhptVDir,
psvd->wzVDirRoot, psvd->pshh);
+ hr = ScaWriteHttpHeader(piMetabase, psvd->wzVDirRoot,
psvd->pshh);
ExitOnFailure(hr, "Failed to write custom HTTP headers for
VirtualDir");
}
if (psvd->pswe)
{
hr = ScaWriteWebError(piMetabase, weptVDir, psvd->wzVDirRoot,
psvd->pswe);
--- scaweb.cpp 2009-02-02 16:34:50.000000000 -0600
+++ scaweb.cpp 2009-02-06 17:06:14.000000000 -0600
@@ -1055,13 +1055,14 @@
ExitOnFailure1(hr, "Failed to write SSL certificates for Web site:
%S", psw->wzKey);
}
// write the headers
if (psw->pshhList)
{
- hr = ScaWriteHttpHeader(piMetabase, hhptWeb, psw->wzWebBase,
psw->pshhList);
+// hr = ScaWriteHttpHeader(piMetabase, hhptWeb, psw->wzWebBase,
psw->pshhList);
+ hr = ScaWriteHttpHeader(piMetabase, wzRootOfWeb, psw->pshhList);
ExitOnFailure1(hr, "Failed to write custom HTTP headers for Web site:
%S", psw->wzKey);
}
// write the errors
if (psw->psweList)
{
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
WiX-devs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wix-devs