ldb: Properly handle NULL when copying attr lists.
authorAndrew Kroeger <andrew@id10ts.net>
Tue, 23 Jun 2009 12:26:17 +0000 (07:26 -0500)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 29 Jun 2009 03:40:08 +0000 (13:40 +1000)
When copying an attribute list, ensure the list itself is not NULL before
attempting to access elements of the list.

source4/lib/ldb/common/ldb_msg.c

index ad53a3d29d27bc0fc1fe376c28d6272cb0c1bf0b..8d0fa313a009280e18b9e951889bdb5538227bda 100644 (file)
@@ -643,12 +643,12 @@ const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs)
 {
        const char **ret;
        int i;
-       for (i=0;attrs[i];i++) /* noop */ ;
+       for (i=0;attrs && attrs[i];i++) /* noop */ ;
        ret = talloc_array(mem_ctx, const char *, i+1);
        if (ret == NULL) {
                return NULL;
        }
-       for (i=0;attrs[i];i++) {
+       for (i=0;attrs && attrs[i];i++) {
                ret[i] = attrs[i];
        }
        ret[i] = attrs[i];
@@ -665,7 +665,7 @@ const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *att
        const char **ret;
        int i;
        bool found = false;
-       for (i=0;attrs[i];i++) {
+       for (i=0;attrs && attrs[i];i++) {
                if (ldb_attr_cmp(attrs[i], new_attr) == 0) {
                        found = true;
                }
@@ -677,7 +677,7 @@ const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *att
        if (ret == NULL) {
                return NULL;
        }
-       for (i=0;attrs[i];i++) {
+       for (i=0;attrs && attrs[i];i++) {
                ret[i] = attrs[i];
        }
        ret[i] = new_attr;