Примеры ошибок, обнаруженных с помощью диагностики V531
V531. The sizeof() operator is multiplied by sizeof(). Consider inspecting the expression.
XUIFramework
V531 It is odd that a sizeof() operator is multiplied by sizeof(). Borne pphtmldrawer.cpp 258
CPPString CPPHtmlDrawer::GetStringFromDll(....)
{
....
TCHAR szTemp[256];
DWORD dwLen = ::LoadString(hInstDll, dwID,
szTemp, (sizeof(szTemp) * sizeof(TCHAR)));
....
}
The LoadString function takes the buffer's size in characters as the last argument. In the Unicode version of the application, we will tell the function that the buffer's size is larger than it is actually. This may cause a buffer overflow. Note that if we fix the code in the following way, it will not become correct at all: sizeof(szTemp) / sizeof(TCHAR).
Similar errors can be found in some other places:
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). Borne pphtmldrawer.cpp 262
NetDefender Firewall
V531 It is odd that a sizeof() operator is multiplied by sizeof(). fire pphtmldrawer.cpp 258
CPPString CPPHtmlDrawer::GetStringFromDll(....)
{
....
TCHAR szTemp[256];
DWORD dwLen = ::LoadString(hInstDll, dwID, szTemp,
(sizeof(szTemp) * sizeof(TCHAR)));
....
}
The LoadString function takes the buffer's size in characters as the last argument. In the Unicode version of the application, we will tell the function that the buffer's size is larger than it is actually. This may cause a buffer overflow. Note that if we fix the code in the following way, it will not become correct at all: sizeof(szTemp) / sizeof(TCHAR).
ReactOS
V531 It is odd that a sizeof() operator is multiplied by sizeof(). eventvwr eventvwr.c 1112
VOID
DisplayEvent(HWND hDlg)
{
WCHAR szEventType[MAX_PATH];
WCHAR szTime[MAX_PATH];
WCHAR szDate[MAX_PATH];
....
ListView_GetItemText(hwndListView, iIndex, 0, szEventType,
sizeof(szEventType) * sizeof(WCHAR));
ListView_GetItemText(hwndListView, iIndex, 1, szDate,
sizeof(szDate) * sizeof(WCHAR));
ListView_GetItemText(hwndListView, iIndex, 2, szTime,
sizeof(szTime) * sizeof(WCHAR));
....
}
ReactOS
V531 It is odd that a sizeof() operator is multiplied by sizeof(). eventvwr.c 1117
VOID
DisplayEvent(HWND hDlg)
{
WCHAR szEventType[MAX_PATH];
WCHAR szTime[MAX_PATH];
WCHAR szDate[MAX_PATH];
WCHAR szUser[MAX_PATH];
WCHAR szComputer[MAX_PATH];
....
ListView_GetItemText(...., sizeof(szEventType)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szDate)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szTime)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szSource)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szCategory)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szEventID)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szUser)*sizeof(WCHAR));
ListView_GetItemText(...., sizeof(szComputer)*sizeof(WCHAR));
....
}
Similar errors can be found in some other places:
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). eventvwr.c 1118
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). eventvwr.c 1119
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). eventvwr.c 1120
- And 4 additional diagnostic messages.
CrashRpt library
V531 It is odd that a sizeof() operator is multiplied by sizeof(). httprequestsender.cpp 286
BOOL CHttpRequestSender::InternalSend()
{
....
TCHAR szBuffer[1024]=_T("");
DWORD dwBuffSize = sizeof(szBuffer)*sizeof(TCHAR);
....
}
Oracle VM Virtual Box
V531 It is odd that a sizeof() operator is multiplied by sizeof(). tstrtfileaio.cpp 61
void
tstFileAioTestReadWriteBasic(...., uint32_t cMaxReqsInFlight)
{
/* Allocate request array. */
RTFILEAIOREQ *paReqs;
paReqs = (...., cMaxReqsInFlight * sizeof(RTFILEAIOREQ));
RTTESTI_CHECK_RETV(paReqs);
RT_BZERO(..., sizeof(cMaxReqsInFlight) * sizeof(RTFILEAIOREQ));
/* Allocate array holding pointer to data buffers. */
void **papvBuf = (...., cMaxReqsInFlight * sizeof(void *));
....
}
CMake
V531 It is odd that a sizeof() operator is multiplied by sizeof(). cmGlobalVisualStudioGenerator.cxx 558
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
const std::string& regKeyBase,
std::string& nextAvailableSubKeyName)
{
....
if (ERROR_SUCCESS == result) {
wchar_t subkeyname[256]; // <=
DWORD cch_subkeyname = sizeof(subkeyname) * sizeof(subkeyname[0]); // <=
wchar_t keyclass[256];
DWORD cch_keyclass = sizeof(keyclass) * sizeof(keyclass[0]);
FILETIME lastWriteTime;
lastWriteTime.dwHighDateTime = 0;
lastWriteTime.dwLowDateTime = 0;
while (ERROR_SUCCESS ==
RegEnumKeyExW(hkey, index, subkeyname, &cch_subkeyname, 0, keyclass,
&cch_keyclass, &lastWriteTime)) {
....
}
....
}
Similar errors can be found in some other places:
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). cmGlobalVisualStudioGenerator.cxx 556
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). cmGlobalVisualStudioGenerator.cxx 572
- V531 It is odd that a sizeof() operator is multiplied by sizeof(). cmGlobalVisualStudioGenerator.cxx 621
- And 2 additional diagnostic messages.
GPCS4
V531 [CWE-131] It is odd that a sizeof() operator is multiplied by sizeof(). sce_gnm_draw.cpp 420
struct GnmCmdPSShader
{
....
uint32_t reserved[27];
};
int PS4API sceGnmSetPsShader350(....)
{
....
memset(param->reserved, 0, sizeof(param->reserved) * sizeof(uint32_t));
return SCE_OK;
}