From d0abb34ae8986870c6966754419259d6a720d13a Mon Sep 17 00:00:00 2001 From: anders_k Date: Fri, 5 Jan 2018 12:53:01 +0000 Subject: [PATCH] Don't allow scripts to delete a HKEY root git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6964 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/exehead/exec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 23f0d695..91589e6d 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -187,7 +187,7 @@ static LONG NSISCALL DeleteRegTree(HKEY hThisKey, LPCTSTR SubKey, REGSAM Samview TCHAR child[MAX_PATH+1]; // NB - don't change this to static (recursive function) while (RegEnumKey(hKey, 0, child, COUNTOF(child)) == ERROR_SUCCESS) { - if (onlyifempty) return (RegCloseKey(hKey), !ERROR_SUCCESS); + if (onlyifempty) return (RegCloseKey(hKey), ERROR_CAN_NOT_COMPLETE); if ((retval = DeleteRegTree(hKey, child, SamviewAndFlags)) != ERROR_SUCCESS) break; } RegCloseKey(hKey); @@ -210,6 +210,7 @@ static LONG NSISCALL DeleteRegTree(HKEY hThisKey, LPCTSTR SubKey, REGSAM Samview static LONG NSISCALL RegDeleteScriptKey(int RootKey, LPCTSTR SubKey, REGSAM SamviewAndFlags) { HKEY hKey; + if (!SubKey[0]) return ERROR_CAN_NOT_COMPLETE; // Don't allow scripts to delete a HKEY root SamviewAndFlags |= KEY_FROMSCRIPT; hKey = GetRegKeyAndSAM(GetRegRootKey(RootKey), &SamviewAndFlags); return hKey ? DeleteRegTree(hKey, SubKey, SamviewAndFlags) : ERROR_INVALID_HANDLE; // ERROR_CANTOPEN?