- fixed two bugs which caused MBCS chars to be treated wrongly in validate_filename and therefore trim too much when validating a path

- converted minus ones to INVALID_FILE_ATTRIBUTES


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3439 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-01-30 23:51:31 +00:00
parent 44ea5c2787
commit 976e1f7097
2 changed files with 25 additions and 21 deletions

View file

@ -243,7 +243,7 @@ __forceinline int NSISCALL ui_doinstall(void)
{ {
DWORD d; DWORD d;
d=GetFileAttributes(p); d=GetFileAttributes(p);
if (d == (DWORD)-1 || !(d&FILE_ATTRIBUTE_DIRECTORY)) if (d == INVALID_FILE_ATTRIBUTES || !(d&FILE_ATTRIBUTE_DIRECTORY))
{ {
// if there is no back-slash, the string will become empty, but that's ok because // if there is no back-slash, the string will become empty, but that's ok because
// it would make an invalid instdir anyway // it would make an invalid instdir anyway

View file

@ -208,31 +208,30 @@ int NSISCALL is_valid_instpath(char *s)
} }
// if the root drive exists // if the root drive exists
if (GetFileAttributes(tmp) == (DWORD)-1) if (GetFileAttributes(tmp) == INVALID_FILE_ATTRIBUTES)
return 0; return 0;
return 1; return 1;
} }
char * NSISCALL mystrstr(char *a, char *b) char * NSISCALL mystrstri(char *a, char *b)
{ {
int len_of_a = mystrlen(a) - mystrlen(b); int l = mystrlen(b);
while (*a && len_of_a >= 0) while (mystrlen(a) >= l)
{ {
char *t=a,*u=b; char c = a[l];
while (*t && *t == *u) a[l] = 0;
if (!lstrcmpi(a, b))
{ {
t++; a[l] = c;
u++; return a;
} }
if (!*u) return a; a[l] = c;
a++; a = CharNext(a);
len_of_a--;
} }
return NULL; return NULL;
} }
void * NSISCALL mini_memcpy(void *out, const void *in, int len) void * NSISCALL mini_memcpy(void *out, const void *in, int len)
{ {
char *c_out=(char*)out; char *c_out=(char*)out;
@ -264,7 +263,8 @@ char * NSISCALL my_GetTempFileName(char *buf, const char *dir)
int n = 100; int n = 100;
while (n--) while (n--)
{ {
char prefix[4] = "nsa"; char prefix[4];
*(LPDWORD)prefix = CHAR4_TO_DWORD('n', 's', 'a', 0);
prefix[2] += (char)(GetTickCount() % 26); prefix[2] += (char)(GetTickCount() % 26);
if (GetTempFileName(dir, prefix, 0, buf)) if (GetTempFileName(dir, prefix, 0, buf))
return buf; return buf;
@ -333,7 +333,7 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
if (pszWinInit != NULL) if (pszWinInit != NULL)
{ {
LPSTR pszRenameSecInFile = mystrstr(pszWinInit, szRenameSec); LPSTR pszRenameSecInFile = mystrstri(pszWinInit, szRenameSec);
if (pszRenameSecInFile == NULL) if (pszRenameSecInFile == NULL)
{ {
mystrcpy(pszWinInit+dwFileSize, szRenameSec); mystrcpy(pszWinInit+dwFileSize, szRenameSec);
@ -343,7 +343,7 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew)
else else
{ {
char *pszFirstRenameLine = pszRenameSecInFile+10; char *pszFirstRenameLine = pszRenameSecInFile+10;
char *pszNextSec = mystrstr(pszFirstRenameLine,"\n["); char *pszNextSec = mystrstri(pszFirstRenameLine,"\n[");
if (pszNextSec) if (pszNextSec)
{ {
char *p = ++pszNextSec; char *p = ++pszNextSec;
@ -583,7 +583,7 @@ char * NSISCALL validate_filename(char *in) {
short cur_char = 0; short cur_char = 0;
char *out; char *out;
char *out_save; char *out_save;
while (*in == ' ') in=CharNext(in); while (*in == ' ') in = CharNext(in);
if (in[0] == '\\' && in[1] == '\\' && in[2] == '?' && in[3] == '\\') { if (in[0] == '\\' && in[1] == '\\' && in[2] == '?' && in[3] == '\\') {
// at least four bytes // at least four bytes
in += 4; in += 4;
@ -594,16 +594,20 @@ char * NSISCALL validate_filename(char *in) {
} }
out = out_save = in; out = out_save = in;
while (*(char*)&cur_char = *in) { while (*(char*)&cur_char = *in) {
if (cur_char > 31 && !mystrstr(nono, (char*)&cur_char)) { if (cur_char > 31 && !mystrstri(nono, (char*)&cur_char)) {
mini_memcpy(out, in, CharNext(in) - in); mini_memcpy(out, in, CharNext(in) - in);
out = CharNext(out); out = CharNext(out);
} }
in = CharNext(in); in = CharNext(in);
} }
*out = 0;
do { do {
*out = 0; out = CharPrev(out_save, out);
--out; if (*out == ' ' || *out == '\\')
} while (out_save <= out && (*out == ' ' || *out == '\\')); *out = 0;
else
break;
} while (out_save < out);
return out_save; return out_save;
} }