4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-19 04:49:25 +08:00

Cygwin: drop last usage of RtlCreateUnicodeStringFromAsciiz

This function is just bad.  It really only works for ASCII
chars, everything else is broken after the conversion.

Introduce new helper function sys_mbstouni to replace
RtlCreateUnicodeStringFromAsciiz in hash_path_name.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2022-08-05 11:45:49 +02:00
parent 249f42d07a
commit d097a96e6e
3 changed files with 18 additions and 3 deletions

View File

@ -1556,7 +1556,8 @@ extern "C"
NTSTATUS RtlCreateAcl (PACL, ULONG, ULONG);
PDEBUG_BUFFER RtlCreateQueryDebugBuffer (ULONG, BOOLEAN);
NTSTATUS RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR, ULONG);
BOOLEAN RtlCreateUnicodeStringFromAsciiz (PUNICODE_STRING, PCSTR);
/* Don't use this function! It's almost always wrong! */
// BOOLEAN RtlCreateUnicodeStringFromAsciiz (PUNICODE_STRING, PCSTR);
NTSTATUS RtlDeleteSecurityObject (PSECURITY_DESCRIPTOR *);
NTSTATUS RtlDestroyQueryDebugBuffer (PDEBUG_BUFFER);
NTSTATUS RtlDowncaseUnicodeString (PUNICODE_STRING, PUNICODE_STRING, BOOLEAN);

View File

@ -3686,9 +3686,11 @@ ino_t
hash_path_name (ino_t hash, const char *name)
{
UNICODE_STRING uname;
RtlCreateUnicodeStringFromAsciiz (&uname, name);
tmp_pathbuf tp;
tp.u_get (&uname);
sys_mbstouni (&uname, HEAP_NOTHEAP, name);
ino_t ret = hash_path_name (hash, &uname);
RtlFreeUnicodeString (&uname);
return ret;
}

View File

@ -91,10 +91,22 @@ sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src,
size_t sys_mbstowcs_alloc (wchar_t **, int, const char *, size_t = (size_t) -1);
static inline size_t
sys_mbstouni (PUNICODE_STRING dst, int type, const char *src,
size_t nms = (size_t) -1)
{
/* sys_mbstowcs returns length *excluding* trailing \0 */
size_t len = sys_mbstowcs (dst->Buffer, type, src, nms);
dst->Length = len * sizeof (WCHAR);
dst->MaximumLength = dst->Length + sizeof (WCHAR);
return dst->Length;
}
static inline size_t
sys_mbstouni_alloc (PUNICODE_STRING dst, int type, const char *src,
size_t nms = (size_t) -1)
{
/* sys_mbstowcs returns length *including* trailing \0 */
size_t len = sys_mbstowcs_alloc (&dst->Buffer, type, src, nms);
dst->MaximumLength = len * sizeof (WCHAR);
dst->Length = dst->MaximumLength - sizeof (WCHAR);