lib: strings: Fix the behavior of strncasecmp_m_handle() in the face of bad conversions.
commit2765daab0a662ba7a3fb75eb0ea09185c9f11891
authorJeremy Allison <jra@samba.org>
Sat, 2 Aug 2014 04:38:59 +0000 (1 21:38 -0700)
committerKarolin Seeger <kseeger@samba.org>
Mon, 1 Sep 2014 19:34:11 +0000 (1 21:34 +0200)
treec698631c4104ef7f31ab8c9e3a5487eda80b9589
parenta8cbd5a9997920b267e94a3070aef0afa94aa8bf
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