From ec5f28969619ba0a60894716fcbd4b9d4ff1dc78 Mon Sep 17 00:00:00 2001 From: kichik Date: Tue, 25 Nov 2003 17:07:40 +0000 Subject: [PATCH] - More path validation (drive id is an english letter, no chars under 32 in a path) - Fixed bug #839214 - message box shown in silent mode if a file can't be opened for writing. Now it will skip the file if AllowSkipFiles is on and abort if it's not. - Added /SD parameter for MessageBox. Allows to set default for silent installers (MessageBox MB_OKCANCEL "OK? Cancel?" /SD IDOK IDOK doOK IDCANCEL doCancel) git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3208 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.cpp | 2 +- Source/exehead/exec.c | 15 ++++++------ Source/exehead/util.c | 13 +++++++--- Source/script.cpp | 57 +++++++++++++++++++++++++++++++++---------- Source/tokens.cpp | 2 +- 5 files changed, 62 insertions(+), 27 deletions(-) diff --git a/Source/build.cpp b/Source/build.cpp index a73ab11d..cda44bf0 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -3179,7 +3179,7 @@ again: // error if (add_label("Initialize_____Plugins_error")) return PS_ERROR; // error message box - ret=add_entry_direct(EW_MESSAGEBOX, MB_OK|MB_ICONSTOP, add_string("Error! Can't initialize plug-ins directory. Please try again later.")); + ret=add_entry_direct(EW_MESSAGEBOX, MB_OK|MB_ICONSTOP|(IDOK<<20), add_string("Error! Can't initialize plug-ins directory. Please try again later.")); if (ret != PS_OK) return ret; // Quit ret=add_entry_direct(EW_QUIT); diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index caee4827..11c95e6b 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -539,19 +539,18 @@ static int NSISCALL ExecuteEntry(entry *entry_) #ifdef NSIS_SUPPORT_RMDIR case EW_RMDIR: { - char *buf0=GetStringFromParm(0x00); - log_printf2("RMDir: \"%s\"",buf0); + char *buf1=GetStringFromParm(-0x10); + log_printf2("RMDir: \"%s\"",buf1); - if (lastchar(buf0)=='\\') trimslashtoend(buf0); - - doRMDir(buf0,parm1); - if (file_exists(buf0) && parm1!=2) exec_error++; - else update_status_text(LANG_REMOVEDIR, buf0); + doRMDir(buf1,parm1); + if (file_exists(buf1) && parm1!=2) exec_error++; + else update_status_text(LANG_REMOVEDIR, buf1); } break; #endif//NSIS_SUPPORT_RMDIR #ifdef NSIS_SUPPORT_STROPTS - case EW_STRLEN: { + case EW_STRLEN: + { char *buf0=GetStringFromParm(0x01); myitoa(var0,mystrlen(buf0)); } diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 6fb56514..a4bfd3c0 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -81,7 +81,11 @@ int NSISCALL my_GetDialogItemText(HWND dlg, UINT idx, char *val, int size) }*/ int NSISCALL my_MessageBox(const char *text, UINT type) { - return MessageBox(g_hwnd, text, g_caption, type); + // default for silent installers + if (g_exec_flags.silent && type >> 20) + return type >> 20; + // no silent or no default, just show + return MessageBox(g_hwnd, text, g_caption, type & 0x000FFFFF); } void * NSISCALL my_GlobalAlloc(DWORD dwBytes) { @@ -135,7 +139,7 @@ char *NSISCALL addtrailingslash(char *str) void NSISCALL trimslashtoend(char *buf) { - char *p = CharPrev(buf, buf + mystrlen(buf)); + char *p = buf + mystrlen(buf); do { if (*p == '\\') @@ -148,7 +152,8 @@ void NSISCALL trimslashtoend(char *buf) int NSISCALL validpathspec(char *ubuf) { - return ((*(WORD*)ubuf==CHAR2_TO_WORD('\\','\\')) || (ubuf[0] && *CharNext(ubuf)==':')); + char dl = ubuf[0] | 0x20; // convert drive letter to lower case + return ((*(WORD*)ubuf==CHAR2_TO_WORD('\\','\\')) || (dl >= 'a' && dl <= 'z' && *CharNext(ubuf)==':')); } char * NSISCALL skip_root(char *path) @@ -710,7 +715,7 @@ char * NSISCALL validate_filename(char *in) { } out = out_save = in; while (*(char*)&cur_char = *in) { - if (!mystrstr(nono, (char*)&cur_char)) { + if (cur_char > 31 && !mystrstr(nono, (char*)&cur_char)) { mini_memcpy(out, in, CharNext(in) - in); out = CharNext(out); } diff --git a/Source/script.cpp b/Source/script.cpp index 70637eb0..84057fa2 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -3314,22 +3314,40 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) 0,IDABORT,IDCANCEL,IDIGNORE,IDNO,IDOK,IDRETRY,IDYES }; const char *retstr="0\0IDABORT\0IDCANCEL\0IDIGNORE\0IDNO\0IDOK\0IDRETRY\0IDYES\0"; + int a=3; if (line.getnumtokens() > 3) { - ent.offsets[2]=line.gettoken_enum(3,retstr); - if (ent.offsets[2] < 0) PRINTHELP() - ent.offsets[2] = rettab[ent.offsets[2]]; - if (process_jump(line,4,&ent.offsets[3])) PRINTHELP() - if (line.getnumtokens() > 5) + if (!strcmpi(line.gettoken_str(3),"/SD")) { - int v=line.gettoken_enum(5,retstr); - if (v < 0) PRINTHELP() - ent.offsets[4] = rettab[v]; - if (process_jump(line,6,&ent.offsets[5])) PRINTHELP() + int k=line.gettoken_enum(4,retstr); + if (k <= 0) PRINTHELP(); + ent.offsets[0]|=rettab[k]<<20; + a=5; + } + else if (line.getnumtokens() > 7) + PRINTHELP(); + + if (line.getnumtokens() > a) + { + ent.offsets[2]=line.gettoken_enum(a,retstr); + if (ent.offsets[2] < 0) + PRINTHELP(); + ent.offsets[2] = rettab[ent.offsets[2]]; + if (process_jump(line,a+1,&ent.offsets[3])) + PRINTHELP(); + if (line.getnumtokens() > a+2) + { + int v=line.gettoken_enum(a+2,retstr); + if (v < 0) + PRINTHELP(); + ent.offsets[4] = rettab[v]; + if (process_jump(line,a+3,&ent.offsets[5])) + PRINTHELP(); + } } } SCRIPT_MSG("MessageBox: %d: \"%s\"",r,line.gettoken_str(2)); - if (line.getnumtokens()>4) SCRIPT_MSG(" (on %s goto %s)",line.gettoken_str(3),line.gettoken_str(4)); + if (line.getnumtokens()>a+1) SCRIPT_MSG(" (on %s goto %s)",line.gettoken_str(a),line.gettoken_str(a+1)); SCRIPT_MSG("\n"); } return add_entry(&ent); @@ -5057,12 +5075,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) DefineInnerLangString(NLF_CANT_WRITE); ent.offsets[0]=1; // overwrite off - ent.offsets[0]|=(MB_ABORTRETRYIGNORE|MB_ICONSTOP)<<3; + ent.offsets[0]|=(MB_RETRYCANCEL|MB_ICONSTOP|(IDCANCEL<<20))<<3; ent.offsets[1]=add_string(tempDLL); ent.offsets[2]=data_handle; ent.offsets[3]=0xffffffff; ent.offsets[4]=0xffffffff; - ent.offsets[5]=MB_ABORTRETRYIGNORE | MB_ICONSTOP; ent.offsets[5]=DefineInnerLangString(NLF_FILE_ERROR); ret=add_entry(&ent); if (ret != PS_OK) { @@ -5321,7 +5338,21 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn } // overwrite flag can be 0, 1, 2 or 3. in all cases, 2 bits - ent.offsets[0] |= ((build_allowskipfiles ? MB_ABORTRETRYIGNORE : MB_RETRYCANCEL) | MB_ICONSTOP) << 3; + int mb = 0; + if (build_allowskipfiles) + { + mb = MB_ABORTRETRYIGNORE | MB_ICONSTOP; + // default for silent installers + mb |= IDIGNORE << 20; + } + else + { + mb = MB_RETRYCANCEL | MB_ICONSTOP; + // default for silent installers + mb |= IDCANCEL << 20; + } + ent.offsets[0] |= mb << 3; + ent.offsets[5] = DefineInnerLangString(build_allowskipfiles ? NLF_FILE_ERROR : NLF_FILE_ERROR_NOIGNORE); } diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 6bf731f3..df06949f 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -110,7 +110,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_LOADNLF,"LoadLanguageFile",1,0,"language.nlf"}, {TOK_LOGSET,"LogSet",1,0,"on|off"}, {TOK_LOGTEXT,"LogText",1,0,"text"}, -{TOK_MESSAGEBOX,"MessageBox",2,4,"mode messagebox_text [return_check label_to_goto_if_equal [return_check2 label2]]\n mode=modeflag[|modeflag[|modeflag[...]]]\n " +{TOK_MESSAGEBOX,"MessageBox",2,6,"mode messagebox_text [/SD return] [return_check label_to_goto_if_equal [return_check2 label2]]\n mode=modeflag[|modeflag[|modeflag[...]]]\n " "modeflag=(MB_ABORTRETRYIGNORE|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND|MB_RIGHT"}, {TOK_NOP,"Nop",0,0,""}, {TOK_NAME,"Name",1,0,"installer_name"},