summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-09-01 04:23:24 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:16:59 -0500
commite424b054d1c9c4c6e1adb4ae7da8232766282c33 (patch)
tree7123af12d5ffd51cf1fbb9d0b9fbc3f9fd80dbd9 /source4
parentf2c083169760db02e267e2ca673e09ff2493931f (diff)
downloadsamba-e424b054d1c9c4c6e1adb4ae7da8232766282c33.tar.gz
samba-e424b054d1c9c4c6e1adb4ae7da8232766282c33.tar.bz2
samba-e424b054d1c9c4c6e1adb4ae7da8232766282c33.zip
r17980: handle NULL arguments without crashing in strcasecmp_m() and
strncasecmp_m(). This makes the use of these functions in sorting routines with RPC replies sane (This used to be commit 93413f84502ff308e88947b9d3bdc9d219478935)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/charset/util_unistr.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c
index 80c1d3b125..e6d929b4e5 100644
--- a/source4/lib/charset/util_unistr.c
+++ b/source4/lib/charset/util_unistr.c
@@ -123,6 +123,11 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
codepoint_t c1=0, c2=0;
size_t size1, size2;
+ /* handle null ptr comparisons to simplify the use in qsort */
+ if (s1 == s2) return 0;
+ if (s1 == NULL) return -1;
+ if (s2 == NULL) return 1;
+
while (*s1 && *s2) {
c1 = next_codepoint(s1, &size1);
c2 = next_codepoint(s2, &size2);
@@ -202,6 +207,11 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
codepoint_t c1=0, c2=0;
size_t size1, size2;
+ /* handle null ptr comparisons to simplify the use in qsort */
+ if (s1 == s2) return 0;
+ if (s1 == NULL) return -1;
+ if (s2 == NULL) return 1;
+
while (*s1 && *s2 && n) {
n--;