Skip to content

Commit

Permalink
[ext] Fix potential bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
killing authored and unknown committed Jun 26, 2015
1 parent 10ca8f8 commit 6ffffb9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
1 change: 1 addition & 0 deletions extensions/applet-connection.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define __STDC_LIMIT_MACROS
#include "ext-common.h"

#include <memory>
Expand Down
23 changes: 17 additions & 6 deletions extensions/context-menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion extensions/icon-overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ STDMETHODIMP ShellExt::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int* pInd

std::string dll = utils::getThisDllPath();

std::unique_ptr<wchar_t> ico(utils::localeToWString(dll));
std::unique_ptr<wchar_t[]> ico(utils::localeToWString(dll));
int wlen = wcslen(ico.get());
if (wlen + 1 > cchMax)
return S_FALSE;
Expand Down

0 comments on commit 6ffffb9

Please sign in to comment.