lib: strings: Fix the behavior of strncasecmp_m_handle() in the face of bad conversions.
authorJeremy Allison <jra@samba.org>
Sat, 2 Aug 2014 04:38:59 +0000 (21:38 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 5 Aug 2014 23:05:14 +0000 (01:05 +0200)
commitdfe8dd87e15bec453c7d3a80c4c707d3f2c7b597
tree0c89a1a8c694ea2528bdc2f763569630f421ad0d
parent9380478a0b292bcb0c11987a88803a37a064d618
lib: strings: Fix the behavior of strncasecmp_m_handle() in the face of bad conversions.

When either string has a bad conversion, we fall back to
doing raw ascii byte comparisons using strcasecmp(). This
is wrong - we should fall back to strncasecmp.

The problem is we've already stepped past the character
that failed the conversion, so we're not re-testing those
characters for comparison. This can have the effect of
causing strncasecmp_m_handle() to report that two strings
are identical when they are not, if the failed conversion
takes place at the end of the string.

The correct behavior is to step back to the point of
the string(s) that failed the conversion, and continue
the test from there.

This is a litle trickier than the previous fix, as
it requires converting the incoming n variable from
remaining characters to compare to remaining bytes to
compare.

As bytes are always the smallest character size
(1 byte) then it's safe to convert the remaining
characters to check by decrementing the source string
by the last character length (in bytes) and incrementing
the remaining bytes to scan by the same value, then
calling strncasecmp() with the stepped back strings
remaining.

Signed-off-by: Jeremy Allison <jra@samba.org>
lib/util/charset/util_str.c