Commit aff9f4c1 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

msi: Fix an off by one error in MsiRecordGetString.

parent 76baa45a
......@@ -321,7 +321,7 @@ UINT MSI_RecordGetStringA(MSIRECORD *rec, unsigned int iField,
break;
}
if( *pcchValue < len )
if( *pcchValue <= len )
ret = ERROR_MORE_DATA;
*pcchValue = len;
......@@ -389,7 +389,7 @@ UINT MSI_RecordGetStringW(MSIRECORD *rec, unsigned int iField,
break;
}
if( *pcchValue < len )
if( *pcchValue <= len )
ret = ERROR_MORE_DATA;
*pcchValue = len;
......
......@@ -51,7 +51,9 @@ static void test_msirecord(void)
INT i;
MSIHANDLE h;
char buf[10];
WCHAR bufW[10];
const char str[] = "hello";
const WCHAR strW[] = { 'h','e','l','l','o',0};
char filename[MAX_PATH];
/* check behaviour with an invalid record */
......@@ -147,6 +149,42 @@ static void test_msirecord(void)
ok(0==strncmp(buf,str,sizeof str-3), "MsiRecordGetString returned the wrong string\n");
ok(buf[sizeof str - 3]==0, "string wasn't nul terminated\n");
buf[0]=0;
sz = sizeof str;
r = MsiRecordGetString(h,0,buf,&sz);
ok(r == ERROR_SUCCESS, "wrong error\n");
ok(sz == sizeof str-1, "MsiRecordGetString returned the wrong length\n");
ok(0==strcmp(buf,str), "MsiRecordGetString returned the wrong string\n");
memset(bufW, 0, sizeof bufW);
sz = 5;
r = MsiRecordGetStringW(h,0,bufW,&sz);
ok(r == ERROR_MORE_DATA, "wrong error\n");
ok(sz == 5, "MsiRecordGetString returned the wrong length\n");
ok(0==memcmp(bufW,strW,8), "MsiRecordGetString returned the wrong string\n");
sz = 0;
bufW[0] = 'x';
r = MsiRecordGetStringW(h,0,bufW,&sz);
ok(r == ERROR_MORE_DATA, "wrong error\n");
ok(sz == 5, "MsiRecordGetString returned the wrong length\n");
ok('x'==bufW[0], "MsiRecordGetString returned the wrong string\n");
memset(buf, 0, sizeof buf);
sz = 5;
r = MsiRecordGetStringA(h,0,buf,&sz);
ok(r == ERROR_MORE_DATA, "wrong error\n");
ok(sz == 5, "MsiRecordGetString returned the wrong length\n");
ok(0==memcmp(buf,str,4), "MsiRecordGetString returned the wrong string\n");
sz = 0;
buf[0] = 'x';
r = MsiRecordGetStringA(h,0,buf,&sz);
ok(r == ERROR_MORE_DATA, "wrong error\n");
ok(sz == 5, "MsiRecordGetString returned the wrong length\n");
ok('x'==buf[0], "MsiRecordGetString returned the wrong string\n");
/* same record, check we can wipe all the data */
r = MsiRecordClearData(h);
ok(r == ERROR_SUCCESS, "Failed to clear record\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment