From 650a51baace048b9c824d2dc111c04a1b5397afb Mon Sep 17 00:00:00 2001 From: anders_k Date: Tue, 15 Nov 2011 17:59:25 +0000 Subject: [PATCH] Added UnsafeStrCpy git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6172 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/script.cpp | 33 +++++++++++++++++++++++++-------- Source/tokens.cpp | 1 + Source/tokens.h | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Source/script.cpp b/Source/script.cpp index c62b8f71..87320a53 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -4947,15 +4947,32 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) SCRIPT_MSG(_T("StrLen %s \"%s\"\n"),line.gettoken_str(1),line.gettoken_str(2)); return add_entry(&ent); case TOK_STRCPY: - ent.which=EW_ASSIGNVAR; - ent.offsets[0]=GetUserVarIndex(line, 1); - ent.offsets[1]=add_string(line.gettoken_str(2)); - ent.offsets[2]=add_string(line.gettoken_str(3)); - ent.offsets[3]=add_string(line.gettoken_str(4)); + case TOK_UNSAFESTRCPY: + { + ent.which = EW_ASSIGNVAR; + const TCHAR* msgprefix = _T(""); + int idx = -1; + if (TOK_STRCPY == which_token) + { + idx = GetUserVarIndex(line, 1); + } + else + { + msgprefix = _T("Unsafe"); + TCHAR *p = line.gettoken_str(1); + if (*p == _T('$') && *++p) idx = m_UserVarNames.get(p); + if (-1 != idx && m_UserVarNames.get_reference(idx) != -1) m_UserVarNames.inc_reference(idx); + } + if (idx < 0) PRINTHELP() + ent.offsets[0]=idx; + ent.offsets[1]=add_string(line.gettoken_str(2)); + ent.offsets[2]=add_string(line.gettoken_str(3)); + ent.offsets[3]=add_string(line.gettoken_str(4)); - if (ent.offsets[0] < 0) PRINTHELP() - SCRIPT_MSG(_T("StrCpy %s \"%s\" (%s) (%s)\n"),line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); - return add_entry(&ent); + SCRIPT_MSG(_T("%sStrCpy %s \"%s\" (%s) (%s)\n"), + msgprefix,line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3),line.gettoken_str(4)); + return add_entry(&ent); + } case TOK_GETFUNCTIONADDR: ent.which=EW_GETFUNCTIONADDR; ent.offsets[0]=GetUserVarIndex(line, 1); diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 39ef29df..aa20fcd2 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -214,6 +214,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_STRCMP,_T("StrCmp"),3,1,_T("str1 str2 label_to_goto_if_equal [label_to_goto_if_not]"),TP_CODE}, {TOK_STRCMPS,_T("StrCmpS"),3,1,_T("str1 str2 label_to_goto_if_equal [label_to_goto_if_not]"),TP_CODE}, {TOK_STRCPY,_T("StrCpy"),2,2,_T("$(user_var: output) str [maxlen] [startoffset]"),TP_CODE}, +{TOK_UNSAFESTRCPY,_T("UnsafeStrCpy"),2,2,_T("$(var: output) str [maxlen] [startoffset]"),TP_CODE}, {TOK_STRLEN,_T("StrLen"),2,0,_T("$(user_var: length output) str"),TP_CODE}, {TOK_SUBCAPTION,_T("SubCaption"),2,0,_T("page_number(0-4) new_subcaption"),TP_GLOBAL}, #ifdef _UNICODE diff --git a/Source/tokens.h b/Source/tokens.h index e6da7f3b..f0b98173 100644 --- a/Source/tokens.h +++ b/Source/tokens.h @@ -203,6 +203,7 @@ enum TOK_SETERRORS, TOK_IFABORT, TOK_STRCPY, + TOK_UNSAFESTRCPY, TOK_STRCMP, TOK_STRCMPS, TOK_GETTEMPFILENAME,