handle NULL strings in strchr_m() and strrchr_m()
authorAndrew Tridgell <tridge@samba.org>
Tue, 30 Sep 2008 20:57:23 +0000 (13:57 -0700)
committerAndrew Tridgell <tridge@samba.org>
Tue, 30 Sep 2008 20:57:23 +0000 (13:57 -0700)
This is needed for the LSA server code which needs to cope with a NULL
names passed to lsa_LookupNames3()

source4/lib/charset/util_unistr.c

index a8ff88423a27adce45101501ea1553bf479a7df0..5f3b2c53f120c9ebefde45211ecb7021dc52b983 100644 (file)
@@ -386,6 +386,9 @@ _PUBLIC_ size_t strlen_m_term(const char *s)
 **/
 _PUBLIC_ char *strchr_m(const char *s, char c)
 {
+       if (s == NULL) {
+               return NULL;
+       }
        /* characters below 0x3F are guaranteed to not appear in
           non-initial position in multi-byte charsets */
        if ((c & 0xC0) == 0) {
@@ -411,6 +414,10 @@ _PUBLIC_ char *strrchr_m(const char *s, char c)
 {
        char *ret = NULL;
 
+       if (s == NULL) {
+               return NULL;
+       }
+
        /* characters below 0x3F are guaranteed to not appear in
           non-initial position in multi-byte charsets */
        if ((c & 0xC0) == 0) {