From 5c63332b4f46a645c80b78bad9b2c9e5959fd0d1 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Wed, 9 Nov 2005 10:59:20 +0000 Subject: [PATCH] Fix passing of NULL pointers to MsiDecomposeDescriptor and add a test. --- dlls/msi/registry.c | 42 +++++++++++++++++++++++++++--------------- dlls/msi/tests/db.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c index b8c206a0d53..ea93320d611 100644 --- a/dlls/msi/registry.c +++ b/dlls/msi/registry.c @@ -253,6 +253,9 @@ BOOL decode_base85_guid( LPCWSTR str, GUID *guid ) { DWORD i, val = 0, base = 1, *p; + if (!str) + return FALSE; + p = (DWORD*) guid; for( i=0; i<20; i++ ) { @@ -532,8 +535,11 @@ UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct, len = (p - &szDescriptor[20]); if( len > MAX_FEATURE_CHARS ) return ERROR_INVALID_PARAMETER; - memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) ); - szFeature[len] = 0; + if (szFeature) + { + memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) ); + szFeature[len] = 0; + } TRACE("feature %s\n", debugstr_w( szFeature )); @@ -543,8 +549,10 @@ UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct, TRACE("component %s\n", debugstr_guid( &component )); - StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 ); - StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 ); + if (szProduct) + StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 ); + if (szComponent) + StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 ); len = ( &p[21] - szDescriptor ); TRACE("length = %d\n", len); @@ -559,26 +567,30 @@ UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct, WCHAR product[MAX_FEATURE_CHARS+1]; WCHAR feature[MAX_FEATURE_CHARS+1]; WCHAR component[MAX_FEATURE_CHARS+1]; - LPWSTR str = NULL; + LPWSTR str = NULL, p = NULL, f = NULL, c = NULL; UINT r; TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct, szFeature, szComponent, pUsed); - if( szDescriptor ) - { - str = strdupAtoW( szDescriptor ); - if( !str ) - return ERROR_OUTOFMEMORY; - } + str = strdupAtoW( szDescriptor ); + if( szDescriptor && !str ) + return ERROR_OUTOFMEMORY; + + if (szProduct) + p = product; + if (szFeature) + f = feature; + if (szComponent) + c = component; - r = MsiDecomposeDescriptorW( str, product, feature, component, pUsed ); + r = MsiDecomposeDescriptorW( str, p, f, c, pUsed ); - WideCharToMultiByte( CP_ACP, 0, product, MAX_FEATURE_CHARS+1, + WideCharToMultiByte( CP_ACP, 0, p, MAX_FEATURE_CHARS+1, szProduct, MAX_FEATURE_CHARS+1, NULL, NULL ); - WideCharToMultiByte( CP_ACP, 0, feature, MAX_FEATURE_CHARS+1, + WideCharToMultiByte( CP_ACP, 0, f, MAX_FEATURE_CHARS+1, szFeature, MAX_FEATURE_CHARS+1, NULL, NULL ); - WideCharToMultiByte( CP_ACP, 0, component, MAX_FEATURE_CHARS+1, + WideCharToMultiByte( CP_ACP, 0, c, MAX_FEATURE_CHARS+1, szComponent, MAX_FEATURE_CHARS+1, NULL, NULL ); msi_free( str ); diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c index 4b167787b34..60c4755ffea 100644 --- a/dlls/msi/tests/db.c +++ b/dlls/msi/tests/db.c @@ -128,7 +128,7 @@ static void test_msiinsert(void) } typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *); -fnMsiDecomposeDescriptorA MsiDecomposeDescriptorA; +static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA; static void test_msidecomposedesc(void) { @@ -141,15 +141,15 @@ static void test_msidecomposedesc(void) hmod = GetModuleHandle("msi.dll"); if (!hmod) return; - MsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA) + pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA) GetProcAddress(hmod, "MsiDecomposeDescriptorA"); - if (!MsiDecomposeDescriptorA) + if (!pMsiDecomposeDescriptorA) return; /* test a valid feature descriptor */ desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk."; len = 0; - r = MsiDecomposeDescriptorA(desc, prod, feature, comp, &len); + r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len); ok(r == ERROR_SUCCESS, "returned an error\n"); ok(len == strlen(desc), "length was wrong\n"); ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n"); @@ -161,7 +161,7 @@ static void test_msidecomposedesc(void) "ThisWillFailIfTheresMoreThanAGuidsChars>" "3w2x^IGfe?CxI5heAvk."; len = 0; - r = MsiDecomposeDescriptorA(desc, prod, feature, comp, &len); + r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len); ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n"); /* @@ -173,9 +173,29 @@ static void test_msidecomposedesc(void) "3w2x^IGfe?CxI5heAvk." "extra"; len = 0; - r = MsiDecomposeDescriptorA(desc, prod, feature, comp, &len); + r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len); ok(r == ERROR_SUCCESS, "returned wrong error\n"); ok(len == (strlen(desc) - strlen("extra")), "length wrong\n"); + + len = 0; + r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len); + ok(r == ERROR_SUCCESS, "returned wrong error\n"); + ok(len == (strlen(desc) - strlen("extra")), "length wrong\n"); + + len = 0; + r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len); + ok(r == ERROR_SUCCESS, "returned wrong error\n"); + ok(len == (strlen(desc) - strlen("extra")), "length wrong\n"); + + len = 0; + r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len); + ok(r == ERROR_SUCCESS, "returned wrong error\n"); + ok(len == (strlen(desc) - strlen("extra")), "length wrong\n"); + + len = 0; + r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len); + ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n"); + ok(len == 0, "length wrong\n"); } static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec ) -- 2.11.4.GIT