From ad0336592146fc46a9f227d90f47563f2a138afb Mon Sep 17 00:00:00 2001 From: anders_k Date: Fri, 18 Jul 2014 16:37:08 +0000 Subject: [PATCH] Don't allow !addincludedir with trailing path separator to propagate to !include git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6526 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/script.cpp | 25 ++++++++----------------- Source/util.cpp | 14 ++++++++++++++ Source/util.h | 8 ++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Source/script.cpp b/Source/script.cpp index 4d461650..e0d77107 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1366,14 +1366,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) SCRIPT_MSG(_T("!delfile: \"%") NPRIs _T("\"\n"), line.gettoken_str(a)); - tstring dir = get_dir_name(fc); - tstring spec = get_file_name(fc); + tstring dir = get_dir_name(fc), spec = get_file_name(fc); tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR; - if (dir == spec) { - // no path, just file name - dir = _T("."); - basedir = _T(""); - } + if (dir == spec) dir = _T("."), basedir = _T(""); // no path, just file name boost::scoped_ptr dr( new_dir_reader() ); dr->read(dir); // BUGBUG: PATH_CONVERT? @@ -3200,12 +3195,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { f = line.gettoken_str(++tok); if (tok >= toks) break; - if(!_tcsicmp(f,_T("/nonfatal"))) { - required = false; - } + if (!_tcsicmp(f,_T("/nonfatal"))) required = false; TCHAR buf[9+1]; my_strncpy(buf,f,COUNTOF(buf)); - if(!_tcsicmp(buf,_T("/charset="))) { + if (!_tcsicmp(buf,_T("/charset="))) { WORD cp = GetEncodingFromString(f+9); if (NStreamEncoding::UNKNOWN == cp) toks = 0; enc.SafeSetCodepage(cp); @@ -3214,9 +3207,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!toks || !*f) PRINTHELP(); TCHAR *fc = my_convert(f); - tstring dir = get_dir_name(fc); - tstring spec = get_file_name(fc); - tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR; + tstring dir = get_dir_name(fc), spec = get_file_name(fc), basedir = dir; + path_append_separator(basedir); if (dir == spec) basedir = _T(""), dir = _T("."); // no path, just file name my_convert_free(fc); @@ -3228,7 +3220,6 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) files_itr++) { if (!dir_reader::matches(*files_itr, spec)) continue; - tstring incfile = basedir + *files_itr; if (includeScript(incfile.c_str(), enc) != PS_OK) return PS_ERROR; @@ -3241,7 +3232,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *incdir = include_dirs.get(); int incdirs = include_dirs.getnum(); for (int i = 0; i < incdirs; i++, incdir += _tcslen(incdir) + 1) { - tstring curincdir = tstring(incdir) + PLATFORM_PATH_SEPARATOR_STR + dir; + tstring curincdir = path_append(tstring(incdir), dir); boost::scoped_ptr dr( new_dir_reader() ); dr->read(curincdir); @@ -3251,7 +3242,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) { if (!dir_reader::matches(*incdir_itr, spec)) continue; - tstring incfile = tstring(incdir) + PLATFORM_PATH_SEPARATOR_STR + basedir + *incdir_itr; + tstring incfile = path_append(tstring(incdir), basedir) + *incdir_itr; if (includeScript(incfile.c_str(), enc) != PS_OK) return PS_ERROR; else diff --git a/Source/util.cpp b/Source/util.cpp index 33c0b10a..57eb966d 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -718,6 +718,20 @@ tstring remove_file_extension(const tstring& path) { return get_string_prefix(path, _T(".")); } +tstring& path_append_separator(tstring& path) +{ + tstring::iterator ib = path.begin(), ie = path.end(); + if (ib != ie && !IsPathSeparator(*--ie)) + path.push_back(PLATFORM_PATH_SEPARATOR_C); + return path; +} + +tstring& path_append(tstring& base, const TCHAR* more) +{ + if (IsPathSeparator(*more)) ++more; + return path_append_separator(base) += more; +} + static int PathGetDosDriveNumber(const TCHAR *p) { // Note: Unlike PathGetDriveNumber(), we require a path separator after the colon. diff --git a/Source/util.h b/Source/util.h index dd2e5b8f..4bccc00c 100644 --- a/Source/util.h +++ b/Source/util.h @@ -48,6 +48,14 @@ tstring get_file_name(const tstring& path); tstring get_executable_path(const TCHAR* argv0); tstring get_executable_dir(const TCHAR *argv0); tstring remove_file_extension(const tstring& path); +tstring& path_append_separator(tstring& path); +tstring& path_append(tstring& base, const TCHAR* more); +inline tstring& path_append(tstring& base, const tstring& more) { return path_append(base, more.c_str()); } +#ifdef _WIN32 +#define IsPathSeparator IsAgnosticPathSeparator +#else +#define IsPathSeparator(c) ( PLATFORM_PATH_SEPARATOR_C == (c) ) +#endif inline bool IsAgnosticPathSeparator(const TCHAR c) { return _T('\\') == c || _T('/') == c; } bool IsWindowsPathRelative(const TCHAR *p);