From bf216dcad6ff26bc9c160402da639fdc89614fb4 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 14 Jul 2008 19:58:16 +0000 Subject: [PATCH] * miscfuncs.cc (cygwin_strncasecmp): Fix bug which results in prematurely truncated strings. Simplify target length argument to sys_mbstowcs. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/miscfuncs.cc | 10 ++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 7bbf33add..0953c1849 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2008-07-14 Corinna Vinschen + + * miscfuncs.cc (cygwin_strncasecmp): Fix bug which results in + prematurely truncated strings. Simplify target length argument to + sys_mbstowcs. + 2008-07-14 Corinna Vinschen * autoload.cc (GetExtendedTcpTable): Define. diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index aff357d1a..845575edf 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -130,16 +130,14 @@ cygwin_strncasecmp (const char *cs, const char *ct, size_t n) while (cs[ls] && ls < n) ++ls; - len = ls * sizeof (WCHAR); + len = (ls + 1) * sizeof (WCHAR); RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len); - us.Length = sys_mbstowcs (us.Buffer, us.MaximumLength / sizeof (WCHAR), - cs, ls) * sizeof (WCHAR); + us.Length = sys_mbstowcs (us.Buffer, ls + 1, cs, ls) * sizeof (WCHAR); while (ct[lt] && lt < n) ++lt; - len = lt * sizeof (WCHAR); + len = (lt + 1) * sizeof (WCHAR); RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len); - ut.Length = sys_mbstowcs (ut.Buffer, ut.MaximumLength / sizeof (WCHAR), - ct, lt) * sizeof (WCHAR); + ut.Length = sys_mbstowcs (ut.Buffer, lt + 1, ct, lt) * sizeof (WCHAR); return RtlCompareUnicodeString (&us, &ut, TRUE); } -- 2.43.5