Bug 13018 - str[n]casecmp_m() doesn't compare based on the lowercase values
Summary: str[n]casecmp_m() doesn't compare based on the lowercase values
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.7.0rc5
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Stefan Metzmacher
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-06 08:12 UTC by Stefan Metzmacher
Modified: 2017-09-17 16:51 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Metzmacher 2017-09-06 08:12:38 UTC
From http://pubs.opengroup.org/onlinepubs/009695399/functions/strcasecmp.html:

...

 In the POSIX locale, strcasecmp() and strncasecmp() shall behave as if the   
 strings had been converted to lowercase and then a byte comparison performed.  
 The results are unspecified in other locales.
...

Currently we get the following results:

strcasecmp(aaaaaaaa,_aaaaaaa) = 2
strcasecmp_m(aaaaaaaa,_aaaaaaa) = 2

strcasecmp(Aaaaaaaa,_aaaaaaa) = 2
strcasecmp_m(Aaaaaaaa,_aaaaaaa) = -30

strcasecmp(Aaaaaaaaa,b_aaaaaaa) = -1
strcasecmp_m(Aaaaaaaaa,b_aaaaaaa) = -33

strcasecmp(aAaaaaaaaa,Bb_aaaaaaa) = -1
strcasecmp_m(aAaaaaaaaa,Bb_aaaaaaa) = 31

This is trivial to fix, but we need to watch out for cases
where we possibly store sorted arrays in persistent databases
and later to binary search on it.

Andrew, do you know about any places where we store sorted arrays in
databases, maybe for ldb indexes?
Comment 1 Andrew Bartlett 2017-09-06 08:33:59 UTC
The ldb index is unsorted, and the schema cache bisection is based on a run-time built table. 

My new GUID patches will be the first time LDB is sorted in the DB, and that is by memcmp() ordering. 

The ldb pack format is not sorted either.
Comment 2 Stefan Metzmacher 2017-09-17 16:51:57 UTC
Pushed v4-{6,7}-test after getting review from slow@samba.org