nwrap: catch NULL list in nwrap_add_hname_add_to_existing
[kai/samba-autobuild/.git] / lib / nss_wrapper / nss_wrapper.c
index 4f9251e72f653a7259a554ac74c6cd8b78dc24d9..064d3d7872ad8dcc4e52cd8c8fb279e744362f62 100644 (file)
@@ -2571,6 +2571,11 @@ static bool nwrap_add_ai(char *const ip_addr, struct nwrap_entdata *const ed)
        ENTRY *p;
        struct nwrap_entlist *el;
 
+       if (ip_addr == NULL) {
+               NWRAP_LOG(NWRAP_LOG_ERROR, "ip_addr NULL - can't add");
+               return false;
+       }
+
        el = nwrap_entlist_init(ed);
        if (el == NULL) {
                return false;
@@ -2596,6 +2601,11 @@ static bool nwrap_add_hname_add_new(char *const h_name,
        ENTRY *p;
        struct nwrap_entlist *el;
 
+       if (h_name == NULL) {
+               NWRAP_LOG(NWRAP_LOG_ERROR, "h_name NULL - can't add");
+               return false;
+       }
+
        el = nwrap_entlist_init(ed);
        if (el == NULL) {
                return false;
@@ -2613,31 +2623,37 @@ static bool nwrap_add_hname_add_new(char *const h_name,
        return true;
 }
 
-static void nwrap_add_hname_add_to_existing(struct nwrap_entdata *const ed,
+static bool nwrap_add_hname_add_to_existing(struct nwrap_entdata *const ed,
                                            struct nwrap_entlist *const el)
 {
        struct nwrap_entlist *cursor;
        struct nwrap_entlist *el_new;
 
+       if (el == NULL) {
+               NWRAP_LOG(NWRAP_LOG_ERROR, "list is NULL, can not add");
+               return false;
+       }
+
        el_new = nwrap_entlist_init(ed);
        if (el_new == NULL) {
-               return;
+               return false;
        }
 
        for (cursor = el; cursor->next != NULL; cursor = cursor->next)
        {
                if (cursor->ed == ed) {
                        free(el_new);
-                       return;
+                       return false;
                }
        }
 
        if (cursor->ed == ed) {
                free(el_new);
-               return;
+               return false;
        }
 
        cursor->next = el_new;
+       return true;
 }
 
 static bool nwrap_add_hname_alias(char *const h_name_a,
@@ -3320,8 +3336,7 @@ static int nwrap_files_gethostbyname(const char *name, int af,
                                     struct hostent *result,
                                     struct nwrap_vector *addr_list)
 {
-       struct nwrap_entlist *el_head;
-       struct nwrap_entlist *el_cur;
+       struct nwrap_entlist *el;
        struct hostent *he;
        char *h_name_lower;
        ENTRY e;
@@ -3370,9 +3385,9 @@ static int nwrap_files_gethostbyname(const char *name, int af,
        }
 
        /* Iterate through results */
-       el_head = (struct nwrap_entlist *)e_p->data;
-       for (el_cur = el_head; el_cur != NULL; el_cur = el_cur->next) {
-               he = &(el_cur->ed->ht);
+       for (el = (struct nwrap_entlist *)e_p->data; el != NULL; el = el->next)
+       {
+               he = &(el->ed->ht);
 
                /* Filter by address familiy if provided */
                if (af != AF_UNSPEC && he->h_addrtype != af) {
@@ -3394,7 +3409,7 @@ static int nwrap_files_gethostbyname(const char *name, int af,
                                  he->h_name);
                        he_found = true;
                }
-               nwrap_vector_merge(addr_list, &el_cur->ed->nwrap_addrdata);
+               nwrap_vector_merge(addr_list, &el->ed->nwrap_addrdata);
                result->h_addr_list = nwrap_vector_head(addr_list);
        }
 
@@ -3480,8 +3495,7 @@ static struct addrinfo *nwrap_files_getaddrinfo(const char *name,
                                                const struct addrinfo *hints,
                                                struct addrinfo **ai_tail)
 {
-       struct nwrap_entlist *el_head;
-       struct nwrap_entlist *el_cur;
+       struct nwrap_entlist *el;
        struct hostent *he;
        struct addrinfo *ai = NULL;
        struct addrinfo *ai_head = NULL;
@@ -3520,12 +3534,11 @@ static struct addrinfo *nwrap_files_getaddrinfo(const char *name,
        NWRAP_LOG(NWRAP_LOG_DEBUG, "Name: %s found.", h_name_lower);
        SAFE_FREE(h_name_lower);
 
-       el_head = (struct nwrap_entlist *)e_p->data;
-
-       for (el_cur = el_head; el_cur != NULL; el_cur = el_cur->next) {
+       for (el = (struct nwrap_entlist *)e_p->data; el != NULL; el = el->next)
+       {
                int rc;
 
-               he = &(el_cur->ed->ht);
+               he = &(el->ed->ht);
 
                if (hints->ai_family != AF_UNSPEC &&
                    he->h_addrtype != hints->ai_family) {