Reputation: 3797
Hi I am getting a Run time Error saying that the stack around szDeviceType
is corrupted but I have no idea, i'm very new to c++ so I wouldn't have the most knowledge. Any help would greatly be appreciated.
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
int szDeviceType = 0;
char lpszString[MAX_PATH];
LPWSTR szComport = NULL;
LPWSTR szNumChannels = NULL;
char szChannels[MAX_PATH];
char szPort[MAX_PATH];
hr = WcaInitialize(hInstall, "GetDatascanInfo");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
hr = WcaGetIntProperty(L"DEVICETYPE",&szDeviceType);
ExitOnFailure(hr, "failed to get Device Type");
hr = WcaGetFormattedProperty(L"COMPORT",&szComport);
ExitOnFailure(hr, "failed to get Com Port");
wcstombs(szPort, szComport, 500);
hr = WcaGetProperty(L"NUMCHANNELS",&szNumChannels);
ExitOnFailure(hr, "failed to get Com Port");
wcstombs(szChannels, szNumChannels, 500);
if(szDeviceType == 2)
{
strcat(lpszString, "datascan");
strcat(lpszString, szPort);
strcat(lpszString, "DATASCAN 7000,DS:");
strcat(lpszString, szChannels);
}
if (szDeviceType == 3)
{
strcat(lpszString, "solo");
strcat(lpszString, szPort);
strcat(lpszString, "DATASCAN SOLO,SA:");
strcat(lpszString, szChannels);
}
if (szDeviceType == 4)
{
strcat(lpszString, "dataweb");
strcat(lpszString, szPort);
strcat(lpszString, "DATAWEB,DW:");
strcat(lpszString, szChannels);
}
hr = MsiSetProperty(hInstall, "DATASCANINFO", lpszString);
ExitOnFailure(hr, "failed to set DATASCANINFO");
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
Upvotes: 0
Views: 148
Reputation: 32398
This looks suss:
wcstombs(szPort, szComport, 500);
The last parameter is the maximum number of characters to write, but your array is only MAX_PATH
in size which is 260.
You're also using strcat
to append to lpszString
without checking whether that overflows. You should probably switch to using strcat_s
which has bounds checking.
Upvotes: 1