From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 46A5B3858C53; Fri, 5 Aug 2022 09:46:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46A5B3858C53 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: drop last usage of RtlCreateUnicodeStringFromAsciiz X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 249f42d07a447ceb6fe22db5a2570f913cb5b4e5 X-Git-Newrev: d097a96e6e5319ab622d5d737c70b21e4a231bec Message-Id: <20220805094605.46A5B3858C53@sourceware.org> Date: Fri, 5 Aug 2022 09:46:05 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Aug 2022 09:46:05 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dd097a96e6e5= 319ab622d5d737c70b21e4a231bec commit d097a96e6e5319ab622d5d737c70b21e4a231bec Author: Corinna Vinschen Date: Fri Aug 5 11:45:49 2022 +0200 Cygwin: drop last usage of RtlCreateUnicodeStringFromAsciiz =20 This function is just bad. It really only works for ASCII chars, everything else is broken after the conversion. =20 Introduce new helper function sys_mbstouni to replace RtlCreateUnicodeStringFromAsciiz in hash_path_name. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/ntdll.h | 3 ++- winsup/cygwin/path.cc | 6 ++++-- winsup/cygwin/wchar.h | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h index bdc1c1e40..0f2310882 100644 --- a/winsup/cygwin/ntdll.h +++ b/winsup/cygwin/ntdll.h @@ -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, BOO= LEAN); diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index b159b56d0..3e436dc65 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -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 =3D hash_path_name (hash, &uname); - RtlFreeUnicodeString (&uname); return ret; } =20 diff --git a/winsup/cygwin/wchar.h b/winsup/cygwin/wchar.h index ff1d4f1fa..0484b27d5 100644 --- a/winsup/cygwin/wchar.h +++ b/winsup/cygwin/wchar.h @@ -91,10 +91,22 @@ sys_mbstowcs (wchar_t * dst, size_t dlen, const char *s= rc, =20 size_t sys_mbstowcs_alloc (wchar_t **, int, const char *, size_t =3D (size= _t) -1); =20 +static inline size_t +sys_mbstouni (PUNICODE_STRING dst, int type, const char *src, + size_t nms =3D (size_t) -1) +{ + /* sys_mbstowcs returns length *excluding* trailing \0 */ + size_t len =3D sys_mbstowcs (dst->Buffer, type, src, nms); + dst->Length =3D len * sizeof (WCHAR); + dst->MaximumLength =3D 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 =3D (size_t) -1) { + /* sys_mbstowcs returns length *including* trailing \0 */ size_t len =3D sys_mbstowcs_alloc (&dst->Buffer, type, src, nms); dst->MaximumLength =3D len * sizeof (WCHAR); dst->Length =3D dst->MaximumLength - sizeof (WCHAR);