Module: wine Branch: refs/heads/master Commit: aff9f4c1ed4ee2b5b16af44e189b4e0715d73591 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=aff9f4c1ed4ee2b5b16af44e...
Author: Mike McCormack mike@codeweavers.com Date: Wed Jul 26 17:43:57 2006 +0900
msi: Fix an off by one error in MsiRecordGetString.
---
dlls/msi/record.c | 4 ++-- dlls/msi/tests/record.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/dlls/msi/record.c b/dlls/msi/record.c index 5b6e38f..159fc0b 100644 --- a/dlls/msi/record.c +++ b/dlls/msi/record.c @@ -321,7 +321,7 @@ UINT MSI_RecordGetStringA(MSIRECORD *rec break; }
- if( *pcchValue < len ) + if( *pcchValue <= len ) ret = ERROR_MORE_DATA; *pcchValue = len;
@@ -389,7 +389,7 @@ UINT MSI_RecordGetStringW(MSIRECORD *rec break; }
- if( *pcchValue < len ) + if( *pcchValue <= len ) ret = ERROR_MORE_DATA; *pcchValue = len;
diff --git a/dlls/msi/tests/record.c b/dlls/msi/tests/record.c index 253d558..f6e11a9 100644 --- a/dlls/msi/tests/record.c +++ b/dlls/msi/tests/record.c @@ -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");