Merge pull request #2301 from RaiKoHoff/grepWin_Integration

Fix .ini-file acquire lock for invalid file path
This commit is contained in:
Rainer Kottenhoff 2020-05-02 22:40:04 +02:00 committed by GitHub
commit 130c6d2912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 72 deletions

View File

@ -1 +1 @@
2
3

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.20.502.2"
version="5.20.502.3"
type="win32"
/>
<description>Notepad3 BETA</description>

View File

@ -784,24 +784,16 @@ static bool _CheckIniFile(LPWSTR lpszFile, LPCWSTR lpszModule)
// ============================================================================
static bool _CheckIniFileRedirect(LPWSTR lpszAppName, LPWSTR lpszKeyName, LPWSTR lpszFile, LPCWSTR lpszModule)
static bool _HandleIniFileRedirect(LPWSTR lpszAppName, LPWSTR lpszKeyName, LPWSTR lpszFile, LPCWSTR lpszModule)
{
WCHAR tch[MAX_PATH] = { L'\0' };
if (IniFileGetString(lpszFile, lpszAppName, lpszKeyName, L"", tch, COUNTOF(tch)))
WCHAR wchPath[MAX_PATH] = { L'\0' };
if (PathFileExists(lpszFile) && IniFileGetString(lpszFile, lpszAppName, lpszKeyName, L"", wchPath, COUNTOF(wchPath)))
{
if (_CheckIniFile(tch, lpszModule)) {
StringCchCopy(lpszFile, MAX_PATH, tch);
return true;
if (!_CheckIniFile(wchPath, lpszModule)) {
PathCanonicalizeEx(wchPath, COUNTOF(wchPath));
}
WCHAR tchFileExpanded[MAX_PATH] = { L'\0' };
ExpandEnvironmentStrings(tch, tchFileExpanded, COUNTOF(tchFileExpanded));
if (PathIsRelative(tchFileExpanded)) {
StringCchCopy(lpszFile, MAX_PATH, lpszModule);
StringCchCopy(PathFindFileName(lpszFile), MAX_PATH, tchFileExpanded);
return true;
}
StringCchCopy(lpszFile, MAX_PATH, tchFileExpanded);
return true;
StringCchCopy(lpszFile, MAX_PATH, wchPath);
return true; // try to use redirection path
}
return false;
}
@ -811,52 +803,50 @@ static bool _CheckIniFileRedirect(LPWSTR lpszAppName, LPWSTR lpszKeyName, LPWST
extern "C" bool FindIniFile()
{
bool bFound = false;
WCHAR tchPath[MAX_PATH] = { L'\0' };
WCHAR tchModule[MAX_PATH] = { L'\0' };
WCHAR tchModule[MAX_PATH] = { L'\0' };
GetModuleFileName(NULL, tchModule, COUNTOF(tchModule));
PathCanonicalizeEx(tchModule, COUNTOF(tchModule));
// set env path to module dir
StringCchCopy(tchPath, COUNTOF(tchPath), tchModule);
PathCchRemoveFileSpec(tchPath, COUNTOF(tchPath));
SetEnvironmentVariable(NOTEPAD3_MODULE_DIR_ENV_VAR, tchPath);
WCHAR wchIniFilePath[MAX_PATH] = { L'\0' };
StringCchCopy(wchIniFilePath, COUNTOF(wchIniFilePath), tchModule);
PathCchRemoveFileSpec(wchIniFilePath, COUNTOF(wchIniFilePath));
if (StrIsNotEmpty(Globals.IniFile)) {
SetEnvironmentVariable(NOTEPAD3_MODULE_DIR_ENV_VAR, wchIniFilePath);
if (StrIsNotEmpty(Globals.IniFile))
{
if (StringCchCompareXI(Globals.IniFile, L"*?") == 0) {
return bFound;
}
if (!_CheckIniFile(Globals.IniFile, tchModule)) {
ExpandEnvironmentStringsEx(Globals.IniFile, COUNTOF(Globals.IniFile));
if (PathIsRelative(Globals.IniFile)) {
StringCchCopy(tchPath, COUNTOF(tchPath), tchModule);
PathCchRemoveFileSpec(tchPath, COUNTOF(tchPath));
PathCchAppend(tchPath, COUNTOF(tchPath), Globals.IniFile);
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), tchPath);
}
}
PathCanonicalizeEx(Globals.IniFile, COUNTOF(Globals.IniFile));
bFound = _CheckIniFile(wchIniFilePath, tchModule);
}
else {
StringCchCopy(tchPath, COUNTOF(tchPath), PathFindFileName(tchModule));
PathCchRenameExtension(tchPath, COUNTOF(tchPath), L".ini");
bFound = _CheckIniFile(tchPath, tchModule);
else
{
StringCchCopy(wchIniFilePath, COUNTOF(wchIniFilePath), PathFindFileName(tchModule));
PathCchRenameExtension(wchIniFilePath, COUNTOF(wchIniFilePath), L".ini");
bFound = _CheckIniFile(wchIniFilePath, tchModule);
if (!bFound) {
StringCchCopy(tchPath, COUNTOF(tchPath), L"Notepad3.ini");
bFound = _CheckIniFile(tchPath, tchModule);
StringCchCopy(wchIniFilePath, COUNTOF(wchIniFilePath), _W(SAPPNAME) L".ini");
bFound = _CheckIniFile(wchIniFilePath, tchModule);
}
if (bFound)
{
// allow two redirections: administrator -> user -> custom
if (_CheckIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", tchPath, tchModule))
if (_HandleIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", wchIniFilePath, tchModule)) // 1st
{
_CheckIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", tchPath, tchModule);
_HandleIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", wchIniFilePath, tchModule); // 2nd
bFound = _CheckIniFile(wchIniFilePath, tchModule);
}
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), tchPath);
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), wchIniFilePath);
}
else {
else // force default name
{
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), tchModule);
PathCchRenameExtension(Globals.IniFile, COUNTOF(Globals.IniFile), L".ini");
}

View File

@ -798,8 +798,8 @@ bool GetKnownFolderPath(REFKNOWNFOLDERID rfid, LPWSTR lpOutPath, size_t cchCount
void PathGetAppDirectory(LPWSTR lpszDest, DWORD cchDest)
{
GetModuleFileName(NULL, lpszDest, cchDest);
PathCanonicalizeEx(lpszDest, cchDest);
PathCchRemoveFileSpec(lpszDest, (size_t)cchDest);
PathCanonicalizeEx(lpszDest, cchDest);
}
@ -884,20 +884,20 @@ void PathAbsoluteFromApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,bool bExpand
}
}
if (bExpandEnv)
ExpandEnvironmentStringsEx(wchPath,COUNTOF(wchPath));
if (bExpandEnv) {
ExpandEnvironmentStringsEx(wchPath, COUNTOF(wchPath));
}
if (PathIsRelative(wchPath)) {
PathGetAppDirectory(wchResult, COUNTOF(wchResult));
PathCchAppend(wchResult,COUNTOF(wchResult),wchPath);
}
else
StringCchCopyN(wchResult,COUNTOF(wchResult),wchPath,COUNTOF(wchPath));
else {
StringCchCopyN(wchResult, COUNTOF(wchResult), wchPath, COUNTOF(wchPath));
}
PathCanonicalizeEx(wchResult,MAX_PATH);
if (PathGetDriveNumber(wchResult) != -1)
CharUpperBuff(wchResult,1);
if (PathGetDriveNumber(wchResult) != -1) {
CharUpperBuff(wchResult, 1);
}
if (lpszDest == NULL || lpszSrc == lpszDest)
StringCchCopyN(lpszSrc,((cchDest == 0) ? MAX_PATH : cchDest),wchResult,COUNTOF(wchResult));
else
@ -975,7 +975,6 @@ bool PathGetLnkPath(LPCWSTR pszLnkFile,LPWSTR pszResPath,int cchResPath)
}
if (bSucceeded) {
ExpandEnvironmentStringsEx(pszResPath,cchResPath);
PathCanonicalizeEx(pszResPath,cchResPath);
}
@ -1321,7 +1320,7 @@ void PathFixBackslashes(LPWSTR lpsz)
//
void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc)
{
WCHAR szBuf[HUGE_BUFFER];
WCHAR szBuf[XXXL_BUFFER];
if (ExpandEnvironmentStrings(lpSrc, szBuf, COUNTOF(szBuf))) {
StringCchCopyN(lpSrc, dwSrc, szBuf, COUNTOF(szBuf));
}
@ -1333,12 +1332,22 @@ void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc)
// PathCanonicalizeEx()
//
//
void PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer)
bool PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchPath)
{
WCHAR szDst[MAX_PATH] = { L'\0' };
if (PathCchCanonicalize(szDst, MAX_PATH, lpszPath) == S_OK) {
StringCchCopy(lpszPath, cchBuffer, szDst);
WCHAR filePath[MAX_PATH] = { L'\0' };
StringCchCopyN(filePath, COUNTOF(filePath), lpszPath, cchPath);
ExpandEnvironmentStringsEx(filePath, COUNTOF(filePath));
if (PathIsRelative(filePath))
{
WCHAR tchModule[MAX_PATH] = { L'\0' };
GetModuleFileName(NULL, tchModule, COUNTOF(tchModule));
PathCchRemoveFileSpec(tchModule, COUNTOF(tchModule));
PathCchAppend(tchModule, COUNTOF(tchModule), lpszPath);
StringCchCopyN(filePath, COUNTOF(filePath), tchModule, COUNTOF(tchModule));
}
return (PathCchCanonicalize(lpszPath, cchPath, filePath) == S_OK);
}
@ -1410,7 +1419,6 @@ void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSo
DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative)
{
WCHAR tmpFilePath[MAX_PATH] = { L'\0' };
StringCchCopyN(tmpFilePath, COUNTOF(tmpFilePath), lpszPath, cchBuffer);
ExpandEnvironmentStringsEx(tmpFilePath, COUNTOF(tmpFilePath));

View File

@ -273,7 +273,7 @@ bool PathCreateDeskLnk(LPCWSTR pszDocument);
bool PathCreateFavLnk(LPCWSTR pszName,LPCWSTR pszTarget,LPCWSTR pszDir);
void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc);
void PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer);
bool PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer);
DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer);
void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSourcePath);
DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative);

View File

@ -6619,7 +6619,6 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
bool bHandled = false;
if (SciCall_IndicatorValueAt(INDIC_NP3_HYPERLINK, position))
{
DocPos const firstPos = SciCall_IndicatorStart(INDIC_NP3_HYPERLINK, position);
DocPos const lastPos = SciCall_IndicatorEnd(INDIC_NP3_HYPERLINK, position);
DocPos const length = min_p(lastPos - firstPos, INTERNET_MAX_URL_LENGTH);
@ -9506,10 +9505,12 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload,
bool bUnknownLexer = s_flagLexerSpecified;
BeginWaitCursor(true,L"Styling...");
if (fSuccess)
if (fSuccess)
{
BeginWaitCursor(true, L"Styling...");
SciCall_GotoPos(0);
if (!s_IsThisAnElevatedRelaunch) {
Flags.bPreserveFileModTime = DefaultFlags.bPreserveFileModTime;
}
@ -9570,11 +9571,12 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload,
_END_UNDO_ACTION_;
SciCall_ScrollToEnd();
}
// set historic caret/selection pos
else if ((iCaretPos >= 0) && (iAnchorPos >= 0))
{
EditSetSelectionEx(iAnchorPos, iCaretPos, 0, 0);
}
}
// set historic caret/selection pos
if ((iCaretPos >= 0) && (iAnchorPos >= 0) && (SciCall_GetCurrentPos() == 0))
{
EditSetSelectionEx(iAnchorPos, iCaretPos, -1, -1);
}
//bReadOnly = false;
@ -9631,12 +9633,13 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload,
Globals.fvCurFile.bTabsAsSpaces = (fioStatus.indentCount[I_TAB_LN] < fioStatus.indentCount[I_SPC_LN]) ? true : false;
SciCall_SetUseTabs(!Globals.fvCurFile.bTabsAsSpaces);
}
EndWaitCursor();
}
else if (!(Flags.bLargeFileLoaded || fioStatus.bUnknownExt)) {
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_LOADFILE, PathFindFileName(szFileName));
}
EndWaitCursor();
UpdateToolbar();
UpdateStatusbar(true);
UpdateMarginWidth();

View File

@ -9,7 +9,7 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 20
#define VERSION_REV 502
#define VERSION_BUILD 2
#define VERSION_BUILD 3
#define SCINTILLA_VER 433
#define ONIGURUMA_REGEX_VER 6.9.5
#define UCHARDET_VER 2018.09.27