From 4ee546e472000293ba70983521ac91628a9259b7 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 21 Jan 2026 01:15:13 -0800 Subject: Protect against NULL User/Group comment when removing comment Fixes 8941 (hopefully) --- src/ext/Util/ca/scaexec.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/ext/Util/ca/scaexec.cpp') diff --git a/src/ext/Util/ca/scaexec.cpp b/src/ext/Util/ca/scaexec.cpp index ee3c164f..2baab86e 100644 --- a/src/ext/Util/ca/scaexec.cpp +++ b/src/ext/Util/ca/scaexec.cpp @@ -764,6 +764,7 @@ extern "C" UINT __stdcall CreateUser( WCA_CASCRIPT_HANDLE hRollbackScript = NULL; int iOriginalAttributes = 0; int iRollbackAttributes = 0; + LPCWSTR wzOriginalComment = NULL; USER_INFO_1 userInfo1; USER_INFO_1* pUserInfo1 = NULL; @@ -885,14 +886,16 @@ extern "C" UINT __stdcall CreateUser( } } - hr = WcaCaScriptWriteString(hRollbackScript, pUserInfo1->usri1_comment); - ExitOnFailure(hr, "Failed to add rollback comment to rollback script."); - - if (!pUserInfo1->usri1_comment || !*pUserInfo1->usri1_comment) + wzOriginalComment = pUserInfo1->usri1_comment; + if (!wzOriginalComment || !*wzOriginalComment) { iRollbackAttributes |= SCAU_REMOVE_COMMENT; + wzOriginalComment = L""; } + hr = WcaCaScriptWriteString(hRollbackScript, wzOriginalComment); + ExitOnFailure(hr, "Failed to add rollback comment to rollback script."); + hr = WcaCaScriptWriteNumber(hRollbackScript, iRollbackAttributes); ExitOnFailure(hr, "Failed to add rollback attributes to rollback script."); @@ -1247,6 +1250,7 @@ extern "C" UINT __stdcall CreateGroup( WCA_CASCRIPT_HANDLE hRollbackScript = NULL; int iRollbackAttributes = 0; + LPCWSTR wzOriginalComment = NULL; DWORD dw; LPWSTR pwzServerName = NULL; @@ -1338,14 +1342,16 @@ extern "C" UINT __stdcall CreateGroup( iRollbackAttributes = 0; - hr = WcaCaScriptWriteString(hRollbackScript, pGroupInfo1->lgrpi1_comment); - ExitOnFailure(hr, "Failed to add rollback comment to rollback script."); - - if (!pGroupInfo1->lgrpi1_comment || !*pGroupInfo1->lgrpi1_comment) + wzOriginalComment = pGroupInfo1->lgrpi1_comment; + if (!wzOriginalComment || !*wzOriginalComment) { iRollbackAttributes |= SCAG_REMOVE_COMMENT; + wzOriginalComment = L""; } + hr = WcaCaScriptWriteString(hRollbackScript, wzOriginalComment); + ExitOnFailure(hr, "Failed to add rollback comment to rollback script."); + hr = WcaCaScriptWriteNumber(hRollbackScript, iRollbackAttributes); ExitOnFailure(hr, "Failed to add rollback attributes to rollback script."); -- cgit v1.2.3-55-g6feb