From 06a515339c840a2c5e337d678e639cd1ff32db41 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 1 Feb 2021 15:35:54 -0500 Subject: [PATCH] Correct pointless and bad buffer sizing in RegisterApplicationRestart --- libs/kiplatform/msw/app.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/kiplatform/msw/app.cpp b/libs/kiplatform/msw/app.cpp index a487a8634f..93a762cd9e 100644 --- a/libs/kiplatform/msw/app.cpp +++ b/libs/kiplatform/msw/app.cpp @@ -30,13 +30,15 @@ bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) { - HRESULT hr = S_OK; // not if registering for recovery and restart fails. - WCHAR wsCommandLine[RESTART_MAX_CMD_LINE]; - RtlZeroMemory( wsCommandLine, sizeof( wsCommandLine ) ); + // Ensure we don't exceed the maximum allowable size + if( aCommandLine.length() > RESTART_MAX_CMD_LINE - 1 ) + { + return false; + } - StringCchCopyW( wsCommandLine, sizeof( wsCommandLine ), aCommandLine.wc_str() ); + HRESULT hr = S_OK; - hr = ::RegisterApplicationRestart( wsCommandLine, RESTART_NO_PATCH ); + hr = ::RegisterApplicationRestart( aCommandLine.wc_str(), RESTART_NO_PATCH ); return SUCCEEDED( hr ); }