Skip to content

Commit c484130

Browse files
authored
Merge pull request pocoproject#2919 from KevDi/bugfix/setFailureActionsCrashes
Fixed Crash in WinService::setFailureActions
2 parents 29f745f + e51adf7 commit c484130

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Util/src/WinService.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,17 @@ WinService::Startup WinService::getStartup() const
236236

237237
void WinService::setFailureActions(FailureActionVector failureActions, const std::string& command, const std::string& rebootMessage)
238238
{
239+
240+
if (failureActions.size() > 3) {
241+
throw InvalidArgumentException{ "Only 0-3 Failure Actions are supported" };
242+
}
243+
239244
open();
240-
auto actions = new SC_ACTION[3];
245+
auto actions = new SC_ACTION[failureActions.size()];
241246
SERVICE_FAILURE_ACTIONSW ac;
242-
247+
ac.lpCommand = NULL;
248+
ac.lpRebootMsg = NULL;
249+
243250
std::wstring urebootMessage;
244251
Poco::UnicodeConverter::toUTF16(rebootMessage, urebootMessage);
245252
std::vector<wchar_t> rebootMessageVector{ urebootMessage.begin(), urebootMessage.end() };
@@ -250,7 +257,7 @@ void WinService::setFailureActions(FailureActionVector failureActions, const std
250257
std::vector<wchar_t> commandVector{ uComamnd.begin(), uComamnd.end() };
251258
commandVector.push_back('\0');
252259

253-
for (auto i = 0; i < 3; i++)
260+
for (auto i = 0; i < failureActions.size(); i++)
254261
{
255262
switch (failureActions[i].type)
256263
{
@@ -276,7 +283,7 @@ void WinService::setFailureActions(FailureActionVector failureActions, const std
276283
}
277284

278285
ac.dwResetPeriod = 0;
279-
ac.cActions = 3;
286+
ac.cActions = failureActions.size();
280287
ac.lpsaActions = actions;
281288

282289
if (!ChangeServiceConfig2W(_svcHandle, SERVICE_CONFIG_FAILURE_ACTIONS, &ac))

0 commit comments

Comments
 (0)