From ce249976f752af1f27afb81f3bdfab33718edd63 Mon Sep 17 00:00:00 2001 From: anders_k Date: Thu, 5 Nov 2015 04:46:14 +0000 Subject: [PATCH] Preprocessor code in dead blocks need to be ignored even if it is invalid Test case: !macro dummy p1 !macroend !if 0 ; The next line does not properly quote its string but it is not !else nor !endif so it has to be ignored !insertmacro dummy "bar' !endif git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6632 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.h | 2 +- Source/lineparse.cpp | 20 +++++++++++++------- Source/script.cpp | 15 +++++++++++---- Source/tokens.cpp | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Source/build.h b/Source/build.h index 12cdf6b7..c37c3471 100644 --- a/Source/build.h +++ b/Source/build.h @@ -176,7 +176,7 @@ class CEXEBuild { void update_exehead(const unsigned char *new_exehead, size_t new_size); // tokens.cpp - bool is_ppbranch_token(TCHAR *s); + bool is_ppbranch_token(const TCHAR *s); bool is_pp_token(int tkid); bool is_unsafe_pp_token(int tkid); int get_commandtoken(const TCHAR *s, int *np, int *op, int *pos); diff --git a/Source/lineparse.cpp b/Source/lineparse.cpp index 1b631b29..3bda35cf 100644 --- a/Source/lineparse.cpp +++ b/Source/lineparse.cpp @@ -150,7 +150,7 @@ double LineParser::gettoken_number(int token, int *success/*=0*/) const TCHAR* LineParser::gettoken_str(int token) const { token+=m_eat; - if (token < 0 || token >= m_nt) return (TCHAR*)_T(""); + if (token < 0 || token >= m_nt) return (TCHAR*) _T(""); return m_tokens[token]; } @@ -201,7 +201,8 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/) else line++; } } - else { + else + { int lstate=0; // 1=", 2=`, 4=' if (*line == _T(';') || *line == _T('#')) { @@ -213,7 +214,8 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/) m_incommentblock = true; line+=2; } - else { + else + { if (*line == _T('\"')) lstate=1; else if (*line == _T('\'')) lstate=2; else if (*line == _T('`')) lstate=4; @@ -222,8 +224,10 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/) TCHAR *p = line; while (*line) { - if (line[0] == _T('$') && line[1] == _T('\\')) { - switch (line[2]) { + if (line[0] == _T('$') && line[1] == _T('\\')) + { + switch (line[2]) + { case _T('"'): case _T('\''): case _T('`'): @@ -247,8 +251,10 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/) int i; m_tokens[m_nt]=(TCHAR*)malloc((nc+1)*sizeof(TCHAR)); for (i = 0; p < line; i++, p++) { - if (!ignore_escaping && p[0] == _T('$') && p[1] == _T('\\')) { - switch (p[2]) { + if (!ignore_escaping && p[0] == _T('$') && p[1] == _T('\\')) + { + switch (p[2]) + { case _T('"'): case _T('\''): case _T('`'): diff --git a/Source/script.cpp b/Source/script.cpp index 5658a7aa..3a32eaec 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -364,11 +364,18 @@ int CEXEBuild::doParse(const TCHAR *str) // if ignoring, ignore all lines that don't begin with an exclamation mark { bool ignore_line = cur_ifblock && (cur_ifblock->ignore || cur_ifblock->inherited_ignore); - TCHAR first_char = *(TCHAR *) m_linebuild.get(); - if (ignore_line && (first_char!=_T('!') || !is_ppbranch_token(line.gettoken_str(0)))) + if (ignore_line) { - m_linebuild.resize(0); - return PS_OK; + TCHAR *rawline = (TCHAR*) m_linebuild.get(), first_char = *rawline, buf[30], *first_token = buf; + if (!res) + first_token = line.gettoken_str(0); + else // LineParser::parse() failed so we cannot call gettoken_str but we still might need to ignore this line + for (size_t i = 0; i < COUNTOF(buf); ++i) if ((buf[i] = rawline[i]) <= ' ') { buf[i] = _T('\0'); break; } + if (first_char!=_T('!') || !is_ppbranch_token(first_token)) + { + m_linebuild.resize(0); + return PS_OK; + } } } diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 84527c8e..f0936c43 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -329,7 +329,7 @@ void CEXEBuild::print_help(const TCHAR *commandname) } -bool CEXEBuild::is_ppbranch_token(TCHAR *s) +bool CEXEBuild::is_ppbranch_token(const TCHAR *s) { int np, op, pos, tkid = get_commandtoken(s, &np, &op, &pos); switch(tkid)