From 6ffffb978a695aefc53c7c26455c9db1165f1e44 Mon Sep 17 00:00:00 2001 From: Jiaqiang Xu Date: Fri, 26 Jun 2015 18:11:04 +0800 Subject: [PATCH] [ext] Fix potential bugs. --- extensions/CMakeLists.txt | 2 +- extensions/applet-connection.cpp | 1 + extensions/context-menu.cpp | 23 +++++++++++++++++------ extensions/icon-overlay.cpp | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 1af0f3311..3b5f25bd7 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -17,7 +17,7 @@ IF (NOT (${CMAKE_BUILD_TYPE} MATCHES Release)) SET(CMAKE_BUILD_TYPE Debug) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g") ENDIF() -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++0x") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fno-omit-frame-pointer -Wall -Wextra -Wno-unused-parameter -std=c++0x") ADD_DEFINITIONS(-D_WIN32_WINNT=${WINVER} -DWINVER=${WINVER}) diff --git a/extensions/applet-connection.cpp b/extensions/applet-connection.cpp index 4db93f058..a2b5254de 100644 --- a/extensions/applet-connection.cpp +++ b/extensions/applet-connection.cpp @@ -1,3 +1,4 @@ +#define __STDC_LIMIT_MACROS #include "ext-common.h" #include diff --git a/extensions/context-menu.cpp b/extensions/context-menu.cpp index 604ff9494..e300e389e 100644 --- a/extensions/context-menu.cpp +++ b/extensions/context-menu.cpp @@ -45,14 +45,16 @@ STDMETHODIMP ShellExt::Initialize_Wrap(LPCITEMIDLIST folder, STGMEDIUM stg = {TYMED_HGLOBAL, {L'\0'}, NULL}; HDROP drop; UINT count; + UINT size; HRESULT result = S_OK; - wchar_t path_w[MAX_PATH+1] = {L'\0'}; + wchar_t path_dir_w[4096]; + wchar_t *path_w = NULL; /* 'folder' param is not null only when clicking at the foler background; When right click on a file, it's NULL */ if (folder) { - if (SHGetPathFromIDListW(folder, path_w)) { - path_ = utils::normalizedPath(utils::wStringToUtf8(path_w)); + if (SHGetPathFromIDListW(folder, path_dir_w)) { + path_ = utils::normalizedPath(utils::wStringToUtf8(path_dir_w)); } } @@ -75,16 +77,25 @@ STDMETHODIMP ShellExt::Initialize_Wrap(LPCITEMIDLIST folder, // count of the characters copied, not including the terminating null // character. count = DragQueryFileW(drop, 0xFFFFFFFF, NULL, 0); - if (count == 0) - result = E_INVALIDARG; - else if (!DragQueryFileW(drop, 0, path_w, MAX_PATH)) + if (count == 0) { result = E_INVALIDARG; + } else { + size = DragQueryFileW(drop, 0, path_w, 0); + if (!size) { + result = E_INVALIDARG; + } else { + path_w = new wchar_t[size+1]; + if (!DragQueryFileW(drop, 0, path_w, size+1)) + result = E_INVALIDARG; + } + } GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); if (result == S_OK) { path_ = utils::normalizedPath(utils::wStringToUtf8(path_w)); + delete[] path_w; } return result; diff --git a/extensions/icon-overlay.cpp b/extensions/icon-overlay.cpp index ca0df9b99..12aac7c36 100644 --- a/extensions/icon-overlay.cpp +++ b/extensions/icon-overlay.cpp @@ -19,7 +19,7 @@ STDMETHODIMP ShellExt::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int* pInd std::string dll = utils::getThisDllPath(); - std::unique_ptr ico(utils::localeToWString(dll)); + std::unique_ptr ico(utils::localeToWString(dll)); int wlen = wcslen(ico.get()); if (wlen + 1 > cchMax) return S_FALSE;