ntdll: Don't use strncasecmp for _strnicmp implementation

Marcus Meissner meissner at suse.de
Tue Oct 16 06:16:54 CDT 2012


On Tue, Oct 16, 2012 at 01:12:50PM +0200, Jacek Caban wrote:
> On 10/16/12 13:08, Marcus Meissner wrote:
> > On Tue, Oct 16, 2012 at 12:38:51PM +0200, Jacek Caban wrote:
> >> ---
> >>  dlls/ntdll/string.c       |   12 +++++++++++-
> >>  dlls/ntdll/tests/string.c |   33 +++++++++++++++++++++++++++++++++
> >>  2 files changed, 44 insertions(+), 1 deletions(-)
> >>
> >>
> >> diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c
> >> index 716dbdf..288e910 100644
> >> --- a/dlls/ntdll/string.c
> >> +++ b/dlls/ntdll/string.c
> >> @@ -254,7 +254,17 @@ int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 )
> >>   */
> >>  int __cdecl _strnicmp( LPCSTR str1, LPCSTR str2, size_t n )
> >>  {
> >> -    return strncasecmp( str1, str2, n );
> >> +    int ret = 0;
> >> +
> >> +    /* 32-bit Windows return only -1,0,1 values */
> >> +    while(n--) {
> >> +        if(!*str1)
> >> +            return sizeof(void*) == 4 ? (*str2 ? -1 : 0) : -(unsigned char)*str2;
> >> +        if((ret = tolower(*str1++) - tolower(*str2++)))
> >> +            return sizeof(void*) == 4 ? (ret > 0 ? 1 : -1) : ret;
> >> +    }
> > Errm. Why not
> >
> > int ret = strncasecmp( str1, str2, n );
> >
> > if (ret < 0 ) return -1;
> > if (ret > 0 ) return 1;
> > return 0;
> 
> That wasn't the original reason for writing this patch. It seems like
> some distros (well, at least some Gentoo installations) have broken
> strncasecmp.

How exactly? Do you know more details / urls?

Does it return -n ... +n values? Like the memcmp optimization that caused mysql security issue?
In that case my patch should work.

Ciao, Marcus



More information about the wine-devel mailing list