Permalink
Browse files

increase resistance to reading configuration when IIS configuration s…

…chema is outdated
  • Loading branch information...
1 parent 1bb44e0 commit 6e46ccc372fcd54b721607ce63821cab3ab41f88 @tjanczuk tjanczuk committed Oct 25, 2012
Showing with 18 additions and 12 deletions.
  1. +17 −11 src/iisnode/cmoduleconfiguration.cpp
  2. +1 −1 src/iisnode/cmoduleconfiguration.h
@@ -441,7 +441,7 @@ HRESULT CModuleConfiguration::GetString(IAppHostElement* section, LPCWSTR proper
return hr;
}
-HRESULT CModuleConfiguration::GetBOOL(IAppHostElement* section, LPCWSTR propertyName, BOOL* value)
+HRESULT CModuleConfiguration::GetBOOL(IAppHostElement* section, LPCWSTR propertyName, BOOL* value, BOOL defaultValue)
{
HRESULT hr = S_OK;
BSTR sysPropertyName = NULL;
@@ -452,10 +452,16 @@ HRESULT CModuleConfiguration::GetBOOL(IAppHostElement* section, LPCWSTR property
*value = FALSE;
VariantInit(&var);
ErrorIf(NULL == (sysPropertyName = SysAllocString(propertyName)), ERROR_NOT_ENOUGH_MEMORY);
- CheckError(section->GetPropertyByName(sysPropertyName, &prop));
- CheckError(prop->get_Value(&var));
- CheckError(VariantChangeType(&var, &var, 0, VT_BOOL));
- *value = (V_BOOL(&var) == VARIANT_TRUE);
+ if (S_OK != section->GetPropertyByName(sysPropertyName, &prop))
+ {
+ *value = defaultValue;
+ }
+ else
+ {
+ CheckError(prop->get_Value(&var));
+ CheckError(VariantChangeType(&var, &var, 0, VT_BOOL));
+ *value = (V_BOOL(&var) == VARIANT_TRUE);
+ }
Error:
@@ -1038,16 +1044,16 @@ HRESULT CModuleConfiguration::GetConfig(IHttpContext* context, CModuleConfigurat
CheckError(GetDWORD(section, L"maxTotalLogFileSizeInKB", &c->maxTotalLogFileSizeInKB));
CheckError(GetDWORD(section, L"maxLogFileSizeInKB", &c->maxLogFileSizeInKB));
CheckError(GetDWORD(section, L"maxLogFiles", &c->maxLogFiles));
- CheckError(GetBOOL(section, L"loggingEnabled", &c->loggingEnabled));
- CheckError(GetBOOL(section, L"devErrorsEnabled", &c->devErrorsEnabled));
- CheckError(GetBOOL(section, L"flushResponse", &c->flushResponse));
+ CheckError(GetBOOL(section, L"loggingEnabled", &c->loggingEnabled, TRUE));
+ CheckError(GetBOOL(section, L"devErrorsEnabled", &c->devErrorsEnabled, TRUE));
+ CheckError(GetBOOL(section, L"flushResponse", &c->flushResponse, FALSE));
CheckError(GetString(section, L"logDirectory", &c->logDirectory));
- CheckError(GetBOOL(section, L"debuggingEnabled", &c->debuggingEnabled));
- CheckError(GetBOOL(section, L"debugHeaderEnabled", &c->debugHeaderEnabled));
+ CheckError(GetBOOL(section, L"debuggingEnabled", &c->debuggingEnabled, TRUE));
+ CheckError(GetBOOL(section, L"debugHeaderEnabled", &c->debugHeaderEnabled, FALSE));
CheckError(GetString(section, L"node_env", &c->node_env));
CheckError(GetString(section, L"debuggerPortRange", &c->debugPortRange));
CheckError(GetString(section, L"watchedFiles", &c->watchedFiles));
- CheckError(GetBOOL(section, L"enableXFF", &c->enableXFF));
+ CheckError(GetBOOL(section, L"enableXFF", &c->enableXFF, FALSE));
CheckError(GetString(section, L"promoteServerVars", &c->promoteServerVarsRaw));
CheckError(GetString(section, L"configOverrides", &c->configOverrides));
CheckError(GetString(section, L"nodeProcessCommandLine", &c->nodeProcessCommandLine));
@@ -49,7 +49,7 @@ class CModuleConfiguration : public IHttpStoredContext
static HTTP_MODULE_ID moduleId;
static HRESULT GetConfigSection(IHttpContext* context, IAppHostElement** section, OLECHAR* configElement = L"system.webServer/iisnode");
static HRESULT GetString(IAppHostElement* section, LPCWSTR propertyName, LPWSTR* value);
- static HRESULT GetBOOL(IAppHostElement* section, LPCWSTR propertyName, BOOL* value);
+ static HRESULT GetBOOL(IAppHostElement* section, LPCWSTR propertyName, BOOL* value, BOOL defaultValue);
static HRESULT GetDWORD(char* str, DWORD* value);
static HRESULT GetBOOL(char* str, BOOL* value);
static HRESULT GetString(char* str, LPWSTR* value);

0 comments on commit 6e46ccc

Please sign in to comment.