msi: Fix some NULL checking in MSI_RecordGetStringA.

Includes a few record tests with a NULL buffer.
This commit is contained in:
Aric Stewart 2008-12-17 10:14:50 -06:00 committed by Alexandre Julliard
parent 5c779bfa0a
commit 17ffb562aa
2 changed files with 14 additions and 3 deletions

View File

@ -358,6 +358,7 @@ UINT MSI_RecordGetStringA(MSIRECORD *rec, UINT iField,
case MSIFIELD_WSTR: case MSIFIELD_WSTR:
len = WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1, len = WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1,
NULL, 0 , NULL, NULL); NULL, 0 , NULL, NULL);
if (szValue)
WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1, WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1,
szValue, *pcchValue, NULL, NULL); szValue, *pcchValue, NULL, NULL);
if( szValue && *pcchValue && len>*pcchValue ) if( szValue && *pcchValue && len>*pcchValue )
@ -366,7 +367,7 @@ UINT MSI_RecordGetStringA(MSIRECORD *rec, UINT iField,
len--; len--;
break; break;
case MSIFIELD_NULL: case MSIFIELD_NULL:
if( *pcchValue > 0 ) if( szValue && *pcchValue > 0 )
szValue[0] = 0; szValue[0] = 0;
break; break;
default: default:

View File

@ -361,6 +361,11 @@ static void test_MsiRecordGetString(void)
rec = MsiCreateRecord(2); rec = MsiCreateRecord(2);
ok(rec != 0, "Expected a valid handle\n"); ok(rec != 0, "Expected a valid handle\n");
sz = MAX_PATH;
r = MsiRecordGetString(rec, 1, NULL, &sz);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n",r);
ok(sz == 0, "Expected 0, got %d\n",sz);
sz = MAX_PATH; sz = MAX_PATH;
lstrcpyA(buf, "apple"); lstrcpyA(buf, "apple");
r = MsiRecordGetString(rec, 1, buf, &sz); r = MsiRecordGetString(rec, 1, buf, &sz);
@ -383,6 +388,11 @@ static void test_MsiRecordGetString(void)
r = MsiRecordSetInteger(rec, 1, 5); r = MsiRecordSetInteger(rec, 1, 5);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
sz = MAX_PATH;
r = MsiRecordGetString(rec, 1, NULL, &sz);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n",r);
ok(sz == 1, "Expected 1, got %d\n",sz);
sz = MAX_PATH; sz = MAX_PATH;
lstrcpyA(buf, "apple"); lstrcpyA(buf, "apple");
r = MsiRecordGetString(rec, 1, buf, &sz); r = MsiRecordGetString(rec, 1, buf, &sz);