From 104cc8af73d98e9e051370051487baa63b01f032 Mon Sep 17 00:00:00 2001 From: Alan Kilborn <77065706+alankilborn@users.noreply.github.com> Date: Fri, 20 Dec 2024 20:32:48 -0500 Subject: [PATCH] Fix crash while passing invalid buffer with NPPM_SETUNTITLEDNAME Fix #15970, close #15975 --- PowerEditor/src/NppBigSwitch.cpp | 1 - PowerEditor/src/NppIO.cpp | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 4d239b4dd..5466bd529 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -3140,7 +3140,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_SETUNTITLEDNAME: { - if (!wParam || !lParam) return FALSE; return fileRenameUntitledPluginAPI(reinterpret_cast(wParam), reinterpret_cast(lParam)); } diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 18c03efa6..5fb852c3d 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -2128,21 +2128,24 @@ bool Notepad_plus::fileRename(BufferID id) bool Notepad_plus::fileRenameUntitledPluginAPI(BufferID id, const wchar_t* tabNewName) { + if (tabNewName == nullptr) return false; + BufferID bufferID = id; if (id == BUFFER_INVALID) { bufferID = _pEditView->getCurrentBufferID(); } - Buffer* buf = MainFileManager.getBufferByID(bufferID); + int bufferIndex = MainFileManager.getBufferIndexByID(bufferID); + if (bufferIndex == -1) return false; - if (!buf->isUntitled()) return false; + Buffer* buf = MainFileManager.getBufferByIndex(bufferIndex); + + if (buf == nullptr || !buf->isUntitled()) return false; // We are just going to rename the tab nothing else // So just rename the tab and rename the backup file too if applicable - if (!tabNewName) return false; - std::wstring tabNewNameStr = tabNewName; trim(tabNewNameStr); // No leading and tailing space allowed