[SETUPAPI] stringtable.c: Code simplification and bugfix.

- Reimplement StringTableInitialize around StringTableInitializeEx
- Fix buffer over-read in StringTableGetExtraData in case the user-specified
  dwExtraDataSize is larger than the dwSize of the pStringTable pData buffer.
This commit is contained in:
Hermès Bélusca-Maïto 2023-09-14 12:29:06 +02:00
parent 56ece9b185
commit f9146968b3
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -57,19 +57,21 @@ typedef struct _STRING_TABLE
/************************************************************************** /**************************************************************************
* StringTableInitialize [SETUPAPI.@] * StringTableInitializeEx [SETUPAPI.@]
* *
* Creates a new string table and initializes it. * Creates a new string table and initializes it.
* *
* PARAMS * PARAMS
* None * dwMaxExtraDataSize [I] Maximum extra data size
* dwReserved [I] Unused
* *
* RETURNS * RETURNS
* Success: Handle to the string table * Success: Handle to the string table
* Failure: NULL * Failure: NULL
*/ */
HSTRING_TABLE WINAPI HSTRING_TABLE WINAPI
StringTableInitialize(VOID) StringTableInitializeEx(DWORD dwMaxExtraDataSize,
DWORD dwReserved)
{ {
PSTRING_TABLE pStringTable; PSTRING_TABLE pStringTable;
@ -95,7 +97,7 @@ StringTableInitialize(VOID)
pStringTable->dwUsedSlots = 0; pStringTable->dwUsedSlots = 0;
pStringTable->dwMaxSlots = TABLE_DEFAULT_SIZE; pStringTable->dwMaxSlots = TABLE_DEFAULT_SIZE;
pStringTable->dwMaxDataSize = 0; pStringTable->dwMaxDataSize = dwMaxExtraDataSize;
TRACE("Done\n"); TRACE("Done\n");
@ -103,47 +105,21 @@ StringTableInitialize(VOID)
} }
/************************************************************************** /**************************************************************************
* StringTableInitializeEx [SETUPAPI.@] * StringTableInitialize [SETUPAPI.@]
* *
* Creates a new string table and initializes it. * Creates a new string table and initializes it.
* *
* PARAMS * PARAMS
* dwMaxExtraDataSize [I] Maximum extra data size * None
* dwReserved [I] Unused
* *
* RETURNS * RETURNS
* Success: Handle to the string table * Success: Handle to the string table
* Failure: NULL * Failure: NULL
*/ */
HSTRING_TABLE WINAPI HSTRING_TABLE WINAPI
StringTableInitializeEx(DWORD dwMaxExtraDataSize, StringTableInitialize(VOID)
DWORD dwReserved)
{ {
PSTRING_TABLE pStringTable; return StringTableInitializeEx(0, 0);
TRACE("\n");
pStringTable = MyMalloc(sizeof(STRING_TABLE));
if (pStringTable == NULL) return NULL;
memset(pStringTable, 0, sizeof(STRING_TABLE));
pStringTable->pSlots = MyMalloc(sizeof(TABLE_SLOT) * TABLE_DEFAULT_SIZE);
if (pStringTable->pSlots == NULL)
{
MyFree(pStringTable);
return NULL;
}
memset(pStringTable->pSlots, 0, sizeof(TABLE_SLOT) * TABLE_DEFAULT_SIZE);
pStringTable->dwUsedSlots = 0;
pStringTable->dwMaxSlots = TABLE_DEFAULT_SIZE;
pStringTable->dwMaxDataSize = dwMaxExtraDataSize;
TRACE("Done\n");
return (HSTRING_TABLE)pStringTable;
} }
/************************************************************************** /**************************************************************************
@ -466,7 +442,7 @@ StringTableGetExtraData(HSTRING_TABLE hStringTable,
memcpy(lpExtraData, memcpy(lpExtraData,
pStringTable->pSlots[dwId - 1].pData, pStringTable->pSlots[dwId - 1].pData,
dwExtraDataSize); pStringTable->pSlots[dwId - 1].dwSize);
return TRUE; return TRUE;
} }