ATL::CAtlStringA buffer management issue fixed
This commit is contained in:
@@ -45,10 +45,10 @@ inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ A
|
|||||||
uiResult = ::MsiGetPropertyA(hInstall, szName, szStackBuffer, &dwSize);
|
uiResult = ::MsiGetPropertyA(hInstall, szName, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
memcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
memcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
@@ -79,10 +79,10 @@ inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_
|
|||||||
uiResult = ::MsiGetPropertyW(hInstall, szName, szStackBuffer, &dwSize);
|
uiResult = ::MsiGetPropertyW(hInstall, szName, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPWSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPWSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
wmemcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
wmemcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
@@ -113,10 +113,10 @@ inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
|
|||||||
uiResult = ::MsiRecordGetStringA(hRecord, iField, szStackBuffer, &dwSize);
|
uiResult = ::MsiRecordGetStringA(hRecord, iField, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
memcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
memcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
@@ -147,10 +147,10 @@ inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
|
|||||||
uiResult = ::MsiRecordGetStringW(hRecord, iField, szStackBuffer, &dwSize);
|
uiResult = ::MsiRecordGetStringW(hRecord, iField, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPWSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPWSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
wmemcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
wmemcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
@@ -181,10 +181,10 @@ inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStr
|
|||||||
uiResult = ::MsiFormatRecordA(hInstall, hRecord, szStackBuffer, &dwSize);
|
uiResult = ::MsiFormatRecordA(hInstall, hRecord, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
memcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
memcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
@@ -215,10 +215,10 @@ inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStr
|
|||||||
uiResult = ::MsiFormatRecordW(hInstall, hRecord, szStackBuffer, &dwSize);
|
uiResult = ::MsiFormatRecordW(hInstall, hRecord, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPWSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPWSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
wmemcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
wmemcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
@@ -271,10 +271,10 @@ inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Ou
|
|||||||
uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szStackBuffer, &dwSize);
|
uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
memcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
memcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
@@ -305,10 +305,10 @@ inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _O
|
|||||||
uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szStackBuffer, &dwSize);
|
uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szStackBuffer, &dwSize);
|
||||||
if (uiResult == NO_ERROR) {
|
if (uiResult == NO_ERROR) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPWSTR szBuffer = sValue.GetBuffer(dwSize + 1);
|
LPWSTR szBuffer = sValue.GetBuffer(dwSize);
|
||||||
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
if (!szBuffer) return ERROR_OUTOFMEMORY;
|
||||||
wmemcpy(szBuffer, szStackBuffer, dwSize); szBuffer[dwSize] = 0;
|
wmemcpy(szBuffer, szStackBuffer, dwSize);
|
||||||
sValue.ReleaseBuffer(dwSize + 1);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
|
@@ -40,13 +40,13 @@ BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ ATL::CAtlStri
|
|||||||
// Try with stack buffer first.
|
// Try with stack buffer first.
|
||||||
if (::GetUserNameExA(NameFormat, szStackBuffer, &ulSize)) {
|
if (::GetUserNameExA(NameFormat, szStackBuffer, &ulSize)) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPSTR szBuffer = sName.GetBuffer(ulSize + 1);
|
LPSTR szBuffer = sName.GetBuffer(ulSize);
|
||||||
if (!szBuffer) {
|
if (!szBuffer) {
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
memcpy(szBuffer, szStackBuffer, ulSize); szBuffer[ulSize] = 0;
|
memcpy(szBuffer, szStackBuffer, ulSize);
|
||||||
sName.ReleaseBuffer(ulSize + 1);
|
sName.ReleaseBuffer(ulSize);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
if (::GetLastError() == ERROR_MORE_DATA) {
|
if (::GetLastError() == ERROR_MORE_DATA) {
|
||||||
@@ -84,13 +84,13 @@ BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ ATL::CAtlStri
|
|||||||
// Try with stack buffer first.
|
// Try with stack buffer first.
|
||||||
if (::GetUserNameExW(NameFormat, szStackBuffer, &ulSize)) {
|
if (::GetUserNameExW(NameFormat, szStackBuffer, &ulSize)) {
|
||||||
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
// Allocate buffer on heap, copy from stack buffer, and zero terminate.
|
||||||
LPWSTR szBuffer = sName.GetBuffer(ulSize + 1);
|
LPWSTR szBuffer = sName.GetBuffer(ulSize);
|
||||||
if (!szBuffer) {
|
if (!szBuffer) {
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
wmemcpy(szBuffer, szStackBuffer, ulSize); szBuffer[ulSize] = 0;
|
wmemcpy(szBuffer, szStackBuffer, ulSize);
|
||||||
sName.ReleaseBuffer(ulSize + 1);
|
sName.ReleaseBuffer(ulSize);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
if (::GetLastError() == ERROR_MORE_DATA) {
|
if (::GetLastError() == ERROR_MORE_DATA) {
|
||||||
|
Reference in New Issue
Block a user