Fix passing of NULL pointers to MsiDecomposeDescriptor and add a

test.
This commit is contained in:
Mike McCormack 2005-11-09 10:59:20 +00:00 committed by Alexandre Julliard
parent 454fa4bea0
commit 5c63332b4f
2 changed files with 53 additions and 21 deletions

View File

@ -253,6 +253,9 @@ BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
{ {
DWORD i, val = 0, base = 1, *p; DWORD i, val = 0, base = 1, *p;
if (!str)
return FALSE;
p = (DWORD*) guid; p = (DWORD*) guid;
for( i=0; i<20; i++ ) for( i=0; i<20; i++ )
{ {
@ -532,8 +535,11 @@ UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
len = (p - &szDescriptor[20]); len = (p - &szDescriptor[20]);
if( len > MAX_FEATURE_CHARS ) if( len > MAX_FEATURE_CHARS )
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) ); if (szFeature)
szFeature[len] = 0; {
memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
szFeature[len] = 0;
}
TRACE("feature %s\n", debugstr_w( szFeature )); 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 )); TRACE("component %s\n", debugstr_guid( &component ));
StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 ); if (szProduct)
StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 ); StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
if (szComponent)
StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
len = ( &p[21] - szDescriptor ); len = ( &p[21] - szDescriptor );
TRACE("length = %d\n", len); TRACE("length = %d\n", len);
@ -559,26 +567,30 @@ UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
WCHAR product[MAX_FEATURE_CHARS+1]; WCHAR product[MAX_FEATURE_CHARS+1];
WCHAR feature[MAX_FEATURE_CHARS+1]; WCHAR feature[MAX_FEATURE_CHARS+1];
WCHAR component[MAX_FEATURE_CHARS+1]; WCHAR component[MAX_FEATURE_CHARS+1];
LPWSTR str = NULL; LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
UINT r; UINT r;
TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct, TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
szFeature, szComponent, pUsed); szFeature, szComponent, pUsed);
if( szDescriptor ) str = strdupAtoW( szDescriptor );
{ if( szDescriptor && !str )
str = strdupAtoW( szDescriptor ); return ERROR_OUTOFMEMORY;
if( !str )
return ERROR_OUTOFMEMORY;
}
r = MsiDecomposeDescriptorW( str, product, feature, component, pUsed ); if (szProduct)
p = product;
if (szFeature)
f = feature;
if (szComponent)
c = component;
WideCharToMultiByte( CP_ACP, 0, product, MAX_FEATURE_CHARS+1, r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
WideCharToMultiByte( CP_ACP, 0, p, MAX_FEATURE_CHARS+1,
szProduct, MAX_FEATURE_CHARS+1, NULL, NULL ); 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 ); 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 ); szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
msi_free( str ); msi_free( str );

View File

@ -128,7 +128,7 @@ static void test_msiinsert(void)
} }
typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *); typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
fnMsiDecomposeDescriptorA MsiDecomposeDescriptorA; static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
static void test_msidecomposedesc(void) static void test_msidecomposedesc(void)
{ {
@ -141,15 +141,15 @@ static void test_msidecomposedesc(void)
hmod = GetModuleHandle("msi.dll"); hmod = GetModuleHandle("msi.dll");
if (!hmod) if (!hmod)
return; return;
MsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA) pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
GetProcAddress(hmod, "MsiDecomposeDescriptorA"); GetProcAddress(hmod, "MsiDecomposeDescriptorA");
if (!MsiDecomposeDescriptorA) if (!pMsiDecomposeDescriptorA)
return; return;
/* test a valid feature descriptor */ /* test a valid feature descriptor */
desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk."; desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
len = 0; 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(r == ERROR_SUCCESS, "returned an error\n");
ok(len == strlen(desc), "length was wrong\n"); ok(len == strlen(desc), "length was wrong\n");
ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n"); ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
@ -161,7 +161,7 @@ static void test_msidecomposedesc(void)
"ThisWillFailIfTheresMoreThanAGuidsChars>" "ThisWillFailIfTheresMoreThanAGuidsChars>"
"3w2x^IGfe?CxI5heAvk."; "3w2x^IGfe?CxI5heAvk.";
len = 0; 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"); ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
/* /*
@ -173,9 +173,29 @@ static void test_msidecomposedesc(void)
"3w2x^IGfe?CxI5heAvk." "3w2x^IGfe?CxI5heAvk."
"extra"; "extra";
len = 0; 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(r == ERROR_SUCCESS, "returned wrong error\n");
ok(len == (strlen(desc) - strlen("extra")), "length wrong\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 ) static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )