* globals.cc (ro_u_scr): New R/O unicode string.
(ro_u_sys): Ditto. * syscalls.cc (nt_path_has_suffix): Replace with ... (nt_path_has_executable_suffix): New function checking for explicit executable suffixes. (rename): Call nt_path_has_executable_suffix instead of nt_path_has_suffix. Check oldpath for nt_path_has_executable_suffix as well to set old_explicit_suffix.
This commit is contained in:
parent
38090b588c
commit
b36d8c46e5
@ -1,3 +1,14 @@
|
|||||||
|
2009-11-06 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* globals.cc (ro_u_scr): New R/O unicode string.
|
||||||
|
(ro_u_sys): Ditto.
|
||||||
|
* syscalls.cc (nt_path_has_suffix): Replace with ...
|
||||||
|
(nt_path_has_executable_suffix): New function checking for explicit
|
||||||
|
executable suffixes.
|
||||||
|
(rename): Call nt_path_has_executable_suffix instead of
|
||||||
|
nt_path_has_suffix. Check oldpath for nt_path_has_executable_suffix
|
||||||
|
as well to set old_explicit_suffix.
|
||||||
|
|
||||||
2009-11-06 Corinna Vinschen <corinna@vinschen.de>
|
2009-11-06 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* shared.cc (inst_root_inited): New static bool variable.
|
* shared.cc (inst_root_inited): New static bool variable.
|
||||||
|
@ -91,6 +91,8 @@ UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
|
|||||||
UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
|
UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
|
||||||
UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
|
UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
|
||||||
UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
|
UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
|
||||||
|
UNICODE_STRING _RDATA ro_u_scr = _ROU (L".scr");
|
||||||
|
UNICODE_STRING _RDATA ro_u_sys = _ROU (L".sys");
|
||||||
UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
|
UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
|
||||||
UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\device\\physicalmemory");
|
UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\device\\physicalmemory");
|
||||||
UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
|
UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
|
||||||
|
@ -1643,27 +1643,36 @@ stop_transaction (NTSTATUS status, HANDLE old_trans, HANDLE trans)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function tests if a filename has *any* suffix. In order to
|
/* This function tests if a filename has one of the "approved" executable
|
||||||
make this quick and simple, we define a suffix as being not longer
|
suffix. This list is probably not complete... */
|
||||||
than 4 chars, plus the leading dot. */
|
|
||||||
static inline bool
|
static inline bool
|
||||||
nt_path_has_suffix (PUNICODE_STRING upath)
|
nt_path_has_executable_suffix (PUNICODE_STRING upath)
|
||||||
{
|
{
|
||||||
|
const PUNICODE_STRING blessed_executable_suffixes[] =
|
||||||
|
{
|
||||||
|
&ro_u_com,
|
||||||
|
&ro_u_exe,
|
||||||
|
&ro_u_scr,
|
||||||
|
&ro_u_sys,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
USHORT pos = upath->Length / sizeof (WCHAR);
|
USHORT pos = upath->Length / sizeof (WCHAR);
|
||||||
const PWCHAR path = upath->Buffer;
|
PWCHAR path;
|
||||||
USHORT upto;
|
UNICODE_STRING usuf;
|
||||||
|
const PUNICODE_STRING *suf;
|
||||||
|
|
||||||
/* Too short for a native path? */
|
/* Too short for a native path? */
|
||||||
if (pos < 8)
|
if (pos < 8)
|
||||||
return false;
|
return false;
|
||||||
upto = pos - 5;
|
/* Assumption: All executable suffixes have a length of three. */
|
||||||
while (--pos >= upto)
|
path = upath->Buffer + pos - 4;
|
||||||
{
|
if (*path != L'.')
|
||||||
if (path[pos] == L'.')
|
return false;
|
||||||
return true;
|
RtlInitCountedUnicodeString (&usuf, path, 4 * sizeof (WCHAR));
|
||||||
if (path[pos] == L'\\')
|
for (suf = blessed_executable_suffixes; *suf; ++suf)
|
||||||
break;
|
if (RtlEqualUnicodeString (&usuf, *suf, TRUE))
|
||||||
}
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1755,9 +1764,10 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
set_errno (ENOTDIR);
|
set_errno (ENOTDIR);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (oldpc.known_suffix
|
if ((oldpc.known_suffix
|
||||||
&& (ascii_strcasematch (oldpath + olen - 4, ".lnk")
|
&& (ascii_strcasematch (oldpath + olen - 4, ".lnk")
|
||||||
|| ascii_strcasematch (oldpath + olen - 4, ".exe")))
|
|| ascii_strcasematch (oldpath + olen - 4, ".exe")))
|
||||||
|
|| nt_path_has_executable_suffix (oldpc.get_nt_native_path ()))
|
||||||
old_explicit_suffix = true;
|
old_explicit_suffix = true;
|
||||||
|
|
||||||
nlen = strlen (newpath);
|
nlen = strlen (newpath);
|
||||||
@ -1865,7 +1875,7 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
&ro_u_lnk, TRUE))
|
&ro_u_lnk, TRUE))
|
||||||
rename_append_suffix (newpc, newpath, nlen, ".lnk");
|
rename_append_suffix (newpc, newpath, nlen, ".lnk");
|
||||||
else if (oldpc.is_binary () && !old_explicit_suffix
|
else if (oldpc.is_binary () && !old_explicit_suffix
|
||||||
&& !nt_path_has_suffix (newpc.get_nt_native_path ()))
|
&& !nt_path_has_executable_suffix (newpc.get_nt_native_path ()))
|
||||||
/* To rename an executable foo.exe to bar-without-suffix, the
|
/* To rename an executable foo.exe to bar-without-suffix, the
|
||||||
.exe suffix must be given explicitly in oldpath. */
|
.exe suffix must be given explicitly in oldpath. */
|
||||||
rename_append_suffix (newpc, newpath, nlen, ".exe");
|
rename_append_suffix (newpc, newpath, nlen, ".exe");
|
||||||
@ -1896,7 +1906,7 @@ rename (const char *oldpath, const char *newpath)
|
|||||||
else if (oldpc.is_binary ())
|
else if (oldpc.is_binary ())
|
||||||
{
|
{
|
||||||
/* Never append .exe suffix if file has any suffix already. */
|
/* Never append .exe suffix if file has any suffix already. */
|
||||||
if (!nt_path_has_suffix (newpc.get_nt_native_path ()))
|
if (!nt_path_has_executable_suffix (newpc.get_nt_native_path ()))
|
||||||
{
|
{
|
||||||
rename_append_suffix (new2pc, newpath, nlen, ".exe");
|
rename_append_suffix (new2pc, newpath, nlen, ".exe");
|
||||||
removepc = &newpc;
|
removepc = &newpc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user