r22589: Make TALLOC_ARRAY consistent across all uses.
authorJeremy Allison <jra@samba.org>
Mon, 30 Apr 2007 02:39:34 +0000 (02:39 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:19:49 +0000 (12:19 -0500)
Jeremy.
(This used to be commit 8968808c3b5b0208cbad9ac92eaf948f2c546dd9)

24 files changed:
source3/auth/auth_util.c
source3/lib/privileges.c
source3/lib/secdesc.c
source3/libaddns/dnsrecord.c
source3/libaddns/dnssock.c
source3/libads/dns.c
source3/libads/ldap.c
source3/libmsrpc/cac_lsarpc.c
source3/libmsrpc/cac_samr.c
source3/libmsrpc/libmsrpc_internal.c
source3/libsmb/clifile.c
source3/modules/vfs_afsacl.c
source3/nsswitch/wb_client.c
source3/nsswitch/winbindd_cache.c
source3/nsswitch/winbindd_passdb.c
source3/nsswitch/winbindd_rpc.c
source3/passdb/lookup_sid.c
source3/printing/notify.c
source3/registry/regfio.c
source3/rpc_client/cli_ds.c
source3/rpc_client/cli_lsarpc.c
source3/rpc_client/cli_samr.c
source3/rpc_client/cli_spoolss.c
source3/rpcclient/cmd_samr.c

index e2bc8e75b5e250be321ddf9673ad1a8d6452e236..db92c50df057acb6fcedade72a543ce00c4fb6bc 100644 (file)
@@ -834,11 +834,15 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
                        goto done;
                }
 
-               group_sids = TALLOC_ARRAY(tmp_ctx, DOM_SID, num_group_sids);
-               if (group_sids == NULL) {
-                       DEBUG(1, ("TALLOC_ARRAY failed\n"));
-                       result = NT_STATUS_NO_MEMORY;
-                       goto done;
+               if (num_group_sids) {
+                       group_sids = TALLOC_ARRAY(tmp_ctx, DOM_SID, num_group_sids);
+                       if (group_sids == NULL) {
+                               DEBUG(1, ("TALLOC_ARRAY failed\n"));
+                               result = NT_STATUS_NO_MEMORY;
+                               goto done;
+                       }
+               } else {
+                       group_sids = NULL;
                }
 
                for (i=0; i<num_group_sids; i++) {
index 5fa9fd7a7d8fdfe7cfda51a659171893983305ff..cd6494d1ed19fd4211ebfec2b474bd740de41aa5 100644 (file)
@@ -719,10 +719,14 @@ NTSTATUS dup_luid_attr(TALLOC_CTX *mem_ctx, LUID_ATTR **new_la, LUID_ATTR *old_l
        if ( !old_la )
                return NT_STATUS_OK;
 
-       *new_la = TALLOC_ARRAY(mem_ctx, LUID_ATTR, count);
-       if ( !*new_la ) {
-               DEBUG(0,("dup_luid_attr: failed to alloc new LUID_ATTR array [%d]\n", count));
-               return NT_STATUS_NO_MEMORY;
+       if (count) {
+               *new_la = TALLOC_ARRAY(mem_ctx, LUID_ATTR, count);
+               if ( !*new_la ) {
+                       DEBUG(0,("dup_luid_attr: failed to alloc new LUID_ATTR array [%d]\n", count));
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               *new_la = NULL;
        }
 
        for (i=0; i<count; i++) {
index 762dc2f6d8cc4fc4df3da94557c701d2ac32b69c..510282bbfb0f533152f6f1ef7a81ca6eaff5a5b2 100644 (file)
@@ -480,8 +480,12 @@ SEC_DESC_BUF *se_create_child_secdesc(TALLOC_CTX *ctx, SEC_DESC *parent_ctr,
 
        the_acl = parent_ctr->dacl;
 
-       if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE, the_acl->num_aces))) 
-               return NULL;
+       if (the_acl->num_aces) {
+               if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE, the_acl->num_aces))) 
+                       return NULL;
+       } else {
+               new_ace_list = NULL;
+       }
 
        for (i = 0; i < the_acl->num_aces; i++) {
                SEC_ACE *ace = &the_acl->aces[i];
index 37a5886af70a86e25fe4653e761c2a8852e88c57..c649dbd7de4b1627e1db038cd46f5fc1624f3fc6 100644 (file)
@@ -234,9 +234,13 @@ DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
 
        if (!ERR_DNS_IS_OK(buf.error)) goto error;
 
-       if (!(tkey->key = TALLOC_ARRAY(tkey, uint8, tkey->key_length))) {
-               buf.error = ERROR_DNS_NO_MEMORY;
-               goto error;
+       if (tkey->key_length) {
+               if (!(tkey->key = TALLOC_ARRAY(tkey, uint8, tkey->key_length))) {
+                       buf.error = ERROR_DNS_NO_MEMORY;
+                       goto error;
+               }
+       } else {
+               tkey->key = NULL;
        }
 
        dns_unmarshall_buffer(&buf, tkey->key, tkey->key_length);
index 5dbedc4fd5164e16159438889cf095b27fc1dc23..6ceefb4e32d4ffea13360be022e9834a0f7be0d0 100644 (file)
@@ -264,9 +264,13 @@ static DNS_ERROR dns_receive_tcp(TALLOC_CTX *mem_ctx,
 
        buf->size = ntohs(len);
 
-       if (!(buf->data = TALLOC_ARRAY(buf, uint8, buf->size))) {
-               TALLOC_FREE(buf);
-               return ERROR_DNS_NO_MEMORY;
+       if (buf->size) {
+               if (!(buf->data = TALLOC_ARRAY(buf, uint8, buf->size))) {
+                       TALLOC_FREE(buf);
+                       return ERROR_DNS_NO_MEMORY;
+               }
+       } else {
+               buf->data = NULL;
        }
 
        err = read_all(conn->s, buf->data, buf->size);
index 008266ea0b0e1e96f8dbcd9866598146f1452954..8b031b0e3a756563b8060d1d933855a41cffaaee 100644 (file)
@@ -283,9 +283,13 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
                
                buf_len = resp_len * sizeof(uint8);
 
-               if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) {
-                       DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n"));
-                       return NT_STATUS_NO_MEMORY;
+               if (buf_len) {
+                       if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) {
+                               DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n"));
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               } else {
+                       buffer = NULL;
                }
 
                if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) {
@@ -499,10 +503,14 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r
        DEBUG(4,("ads_dns_lookup_ns: %d records returned in the answer section.\n", 
                answer_count));
                
-       if ( (nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns, answer_count)) == NULL ) {
-               DEBUG(0,("ads_dns_lookup_ns: talloc() failure for %d char*'s\n", 
-                       answer_count));
-               return NT_STATUS_NO_MEMORY;
+       if (answer_count) {
+               if ( (nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns, answer_count)) == NULL ) {
+                       DEBUG(0,("ads_dns_lookup_ns: talloc() failure for %d char*'s\n", 
+                               answer_count));
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               nsarray = NULL;
        }
 
        /* now skip the header */
index 6707cbd4d0fc1eb1209b4d4874618fd6095303fe..5a34385c32a3c96c061b4e76b64a527126908020 100644 (file)
@@ -2225,10 +2225,14 @@ int ads_count_replies(ADS_STRUCT *ads, void *res)
        for (i=0; values[i]; i++)
                /* nop */ ;
 
-       (*sids) = TALLOC_ARRAY(mem_ctx, DOM_SID, i);
-       if (!(*sids)) {
-               ldap_value_free_len(values);
-               return 0;
+       if (i) {
+               (*sids) = TALLOC_ARRAY(mem_ctx, DOM_SID, i);
+               if (!(*sids)) {
+                       ldap_value_free_len(values);
+                       return 0;
+               }
+       } else {
+               (*sids) = NULL;
        }
 
        count = 0;
index 2e3eb276d5adb68a88641dec695e052b68141d42..de53c0f483a455bb980caf960b966e0a27d545c2 100644 (file)
@@ -203,11 +203,15 @@ int cac_LsaGetNamesFromSids( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
 
        if ( NT_STATUS_IS_OK( hnd->status ) ) {
                /*this is the easy part, just make the out.sids array */
-               sids_out = TALLOC_ARRAY( mem_ctx, CacSidInfo, num_sids );
-               if ( !sids_out ) {
-                       errno = ENOMEM;
-                       hnd->status = NT_STATUS_NO_MEMORY;
-                       return CAC_FAILURE;
+               if (num_sids) {
+                       sids_out = TALLOC_ARRAY( mem_ctx, CacSidInfo, num_sids );
+                       if ( !sids_out ) {
+                               errno = ENOMEM;
+                               hnd->status = NT_STATUS_NO_MEMORY;
+                               return CAC_FAILURE;
+                       }
+               } else {
+                       sids_out = NULL;
                }
 
                for ( i = 0; i < num_sids; i++ ) {
@@ -232,22 +236,29 @@ int cac_LsaGetNamesFromSids( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
                        return CAC_FAILURE;
                }
 
-               sids_out =
-                       TALLOC_ARRAY( mem_ctx, CacSidInfo,
+               if ( num_sids - num_unknown) {
+                       sids_out =
+                               TALLOC_ARRAY( mem_ctx, CacSidInfo,
                                      ( num_sids - num_unknown ) );
-               if ( !sids_out ) {
-                       errno = ENOMEM;
-                       hnd->status = NT_STATUS_NO_MEMORY;
-                       return CAC_FAILURE;
+                       if ( !sids_out ) {
+                               errno = ENOMEM;
+                               hnd->status = NT_STATUS_NO_MEMORY;
+                               return CAC_FAILURE;
+                       }
+               } else {
+                       sids_out = NULL;
                }
 
-               unknown_out = TALLOC_ARRAY( mem_ctx, DOM_SID, num_unknown );
-               if ( !unknown_out ) {
-                       errno = ENOMEM;
-                       hnd->status = NT_STATUS_NO_MEMORY;
-                       return CAC_FAILURE;
+               if (num_unknown) {
+                       unknown_out = TALLOC_ARRAY( mem_ctx, DOM_SID, num_unknown );
+                       if ( !unknown_out ) {
+                               errno = ENOMEM;
+                               hnd->status = NT_STATUS_NO_MEMORY;
+                               return CAC_FAILURE;
+                       }
+               } else {
+                       unknown_out = NULL;
                }
-
                found_idx = unknown_idx = 0;
 
                /*now we can actually do the real work */
@@ -330,11 +341,15 @@ int cac_LsaGetSidsFromNames( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
 
        if ( NT_STATUS_IS_OK( hnd->status ) ) {
                /*this is the easy part, just make the out.sids array */
-               sids_out = TALLOC_ARRAY( mem_ctx, CacSidInfo, num_names );
-               if ( !sids_out ) {
-                       errno = ENOMEM;
-                       hnd->status = NT_STATUS_NO_MEMORY;
-                       return CAC_FAILURE;
+               if (num_names) {
+                       sids_out = TALLOC_ARRAY( mem_ctx, CacSidInfo, num_names );
+                       if ( !sids_out ) {
+                               errno = ENOMEM;
+                               hnd->status = NT_STATUS_NO_MEMORY;
+                               return CAC_FAILURE;
+                       }
+               } else {
+                       sids_out = NULL;
                }
 
                for ( i = 0; i < num_names; i++ ) {
@@ -360,20 +375,28 @@ int cac_LsaGetSidsFromNames( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
                        return CAC_FAILURE;
                }
 
-               sids_out =
-                       TALLOC_ARRAY( mem_ctx, CacSidInfo,
+               if (num_names - num_unknown) {
+                       sids_out =
+                               TALLOC_ARRAY( mem_ctx, CacSidInfo,
                                      ( num_names - num_unknown ) );
-               if ( !sids_out ) {
-                       errno = ENOMEM;
-                       hnd->status = NT_STATUS_NO_MEMORY;
-                       return CAC_FAILURE;
+                       if ( !sids_out ) {
+                               errno = ENOMEM;
+                               hnd->status = NT_STATUS_NO_MEMORY;
+                               return CAC_FAILURE;
+                       }
+               } else {
+                       sids_out = NULL;
                }
 
-               unknown_out = TALLOC_ARRAY( mem_ctx, char *, num_unknown );
-               if ( !unknown_out ) {
-                       errno = ENOMEM;
-                       hnd->status = NT_STATUS_NO_MEMORY;
-                       return CAC_FAILURE;
+               if (num_unknown) {
+                       unknown_out = TALLOC_ARRAY( mem_ctx, char *, num_unknown );
+                       if ( !unknown_out ) {
+                               errno = ENOMEM;
+                               hnd->status = NT_STATUS_NO_MEMORY;
+                               return CAC_FAILURE;
+                       }
+               } else {
+                       unknown_out = NULL;
                }
 
                unknown_idx = found_idx = 0;
index e50fb474f51ca99d27ab2bccab034cd6e26d85a4..4d3acc85e3afb42ee62d00aae4a4ba6514cfa4a5 100644 (file)
@@ -557,10 +557,14 @@ int cac_SamGetNamesFromRids( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
             && !NT_STATUS_EQUAL( hnd->status, STATUS_SOME_UNMAPPED ) )
                return CAC_FAILURE;
 
-       map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_names_out );
-       if ( !map_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
+       if (num_names_out) {
+               map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_names_out );
+               if ( !map_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+       } else {
+               map_out = NULL;
        }
 
        for ( i = 0; i < num_names_out; i++ ) {
@@ -643,10 +647,14 @@ int cac_SamGetRidsFromNames( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
             && !NT_STATUS_EQUAL( hnd->status, STATUS_SOME_UNMAPPED ) )
                return CAC_FAILURE;
 
-       map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_rids_out );
-       if ( !map_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
+       if (num_rids_out) {
+               map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_rids_out );
+               if ( !map_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+       } else {
+               map_out = NULL;
        }
 
        for ( i = 0; i < num_rids_out; i++ ) {
@@ -718,16 +726,20 @@ int cac_SamGetGroupsForUser( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
                return CAC_FAILURE;
 
 
-       rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
-       if ( !rids_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
-       }
-
-       attr_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
-       if ( !attr_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
+       if (num_groups_out) {
+               rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
+               if ( !rids_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+               attr_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
+               if ( !attr_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+       } else {
+               rids_out = NULL;
+               attr_out = NULL;
        }
 
        for ( i = 0; i < num_groups_out; i++ ) {
@@ -1153,28 +1165,34 @@ int cac_SamEnumGroups( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
                return CAC_FAILURE;
        }
 
-       names_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
-       if ( !names_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               return CAC_FAILURE;
-       }
+       if (num_groups_out) {
+               names_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
+               if ( !names_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       return CAC_FAILURE;
+               }
 
-       desc_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
-       if ( !desc_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               return CAC_FAILURE;
-       }
+               desc_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
+               if ( !desc_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       return CAC_FAILURE;
+               }
 
-       rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
-       if ( !rids_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               TALLOC_FREE( desc_out );
-               return CAC_FAILURE;
+               rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
+               if ( !rids_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       TALLOC_FREE( desc_out );
+                       return CAC_FAILURE;
+               }
+       } else {
+               names_out = NULL;
+               desc_out = NULL;
+               rids_out = NULL;
        }
 
        for ( i = 0; i < num_groups_out; i++ ) {
@@ -1256,28 +1274,34 @@ int cac_SamEnumAliases( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
             NT_STATUS_V( STATUS_MORE_ENTRIES ) )
                return CAC_FAILURE;
 
-       names_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
-       if ( !names_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               return CAC_FAILURE;
-       }
+       if (num_als_out) {
+               names_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
+               if ( !names_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       return CAC_FAILURE;
+               }
 
-       desc_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
-       if ( !desc_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               return CAC_FAILURE;
-       }
+               desc_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
+               if ( !desc_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       return CAC_FAILURE;
+               }
 
-       rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_als_out );
-       if ( !rids_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               TALLOC_FREE( desc_out );
-               return CAC_FAILURE;
+               rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_als_out );
+               if ( !rids_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       TALLOC_FREE( desc_out );
+                       return CAC_FAILURE;
+               }
+       } else {
+               names_out = NULL;
+               desc_out = NULL;
+               rids_out = NULL;
        }
 
        for ( i = 0; i < num_als_out; i++ ) {
index 64e6332e804a2b27118ce01c5ea9d240077a05cc..3cb702e376759bd422ff123d1e7d684bcfafe1f4 100644 (file)
@@ -299,12 +299,16 @@ REG_VALUE_DATA *cac_MakeRegValueData( TALLOC_CTX * mem_ctx, uint32 data_type,
                                break;
                }
 
-               strings = TALLOC_ARRAY( mem_ctx, char *, num_strings );
+               if (num_strings) {
+                       strings = TALLOC_ARRAY( mem_ctx, char *, num_strings );
 
-               if ( !strings ) {
-                       errno = ENOMEM;
-                       TALLOC_FREE( data );
-                       break;
+                       if ( !strings ) {
+                               errno = ENOMEM;
+                               TALLOC_FREE( data );
+                               break;
+                       }
+               } else {
+                       strings = NULL;
                }
 
                if ( num_strings == 0 ) /*then our work here is done */
index ad6029f2243674782d0a630b53016c84efb4be15..2e1c156f14ad7ee335b87fe5a35636338c7530e2 100644 (file)
@@ -1692,9 +1692,13 @@ static BOOL cli_get_ea_list(struct cli_state *cli,
                goto out;
        }
 
-       ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);
-       if (!ea_list) {
-               goto out;
+       if (num_eas) {
+               ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);
+               if (!ea_list) {
+                       goto out;
+               }
+       } else {
+               ea_list = NULL;
        }
 
        ea_size = (size_t)IVAL(rdata,0);
index 43fa537d734aa9cbe31b42e5d5a1287ac4037bc6..a82e6b350b2c19c74ffa67aecf550eb1bc0c8139 100644 (file)
@@ -616,10 +616,14 @@ static size_t afs_to_nt_acl(struct afs_acl *afs_acl,
        uid_to_sid(&owner_sid, sbuf.st_uid);
        gid_to_sid(&group_sid, sbuf.st_gid);
 
-       nt_ace_list = TALLOC_ARRAY(mem_ctx, SEC_ACE, afs_acl->num_aces);
+       if (num_aces) {
+               nt_ace_list = TALLOC_ARRAY(mem_ctx, SEC_ACE, afs_acl->num_aces);
 
-       if (nt_ace_list == NULL)
-               return 0;
+               if (nt_ace_list == NULL)
+                       return 0;
+       } else {
+               nt_ace_list = NULL;
+       }
 
        afs_ace = afs_acl->acelist;
        good_aces = 0;
index afb62027544251b6ddcbe8ac60e714e4a547652e..25fbefc45e1742cca66a2516a7ce3f7893b6abc1 100644 (file)
@@ -165,11 +165,16 @@ BOOL winbind_lookup_rids(TALLOC_CTX *mem_ctx,
 
        *domain_name = talloc_strdup(mem_ctx, response.data.domain_name);
 
-       *names = TALLOC_ARRAY(mem_ctx, const char *, num_rids);
-       *types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_rids);
+       if (num_rids) {
+               *names = TALLOC_ARRAY(mem_ctx, const char *, num_rids);
+               *types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_rids);
 
-       if ((*names == NULL) || (*types == NULL)) {
-               goto fail;
+               if ((*names == NULL) || (*types == NULL)) {
+                       goto fail;
+               }
+       } else {
+               *names = NULL;
+               *types = NULL;
        }
 
        p = (char *)response.extra_data.data;
index da8983dda25b57692c068638b44b4d2990ad79bb..47bd872f0301a21d7d194245bb626997ad866e1b 100644 (file)
@@ -1794,11 +1794,15 @@ static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
        *num_aliases = centry_uint32(centry);
        *alias_rids = NULL;
 
-       (*alias_rids) = TALLOC_ARRAY(mem_ctx, uint32, *num_aliases);
+       if (*num_aliases) {
+               (*alias_rids) = TALLOC_ARRAY(mem_ctx, uint32, *num_aliases);
 
-       if ((*num_aliases != 0) && ((*alias_rids) == NULL)) {
-               centry_free(centry);
-               return NT_STATUS_NO_MEMORY;
+               if ((*alias_rids) == NULL) {
+                       centry_free(centry);
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               (*alias_rids) = NULL;
        }
 
        for (i=0; i<(*num_aliases); i++)
@@ -1962,15 +1966,21 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
  
        *num_domains = centry_uint32(centry);
        
-       (*names)        = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
-       (*alt_names)    = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
-       (*dom_sids)     = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_domains);
+       if (*num_domains) {
+               (*names)        = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
+               (*alt_names)    = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
+               (*dom_sids)     = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_domains);
  
-       if (! (*dom_sids) || ! (*names) || ! (*alt_names)) {
-               smb_panic_fn("trusted_domains out of memory");
-               centry_free(centry);
-               return NT_STATUS_NO_MEMORY;
-       }
+               if (! (*dom_sids) || ! (*names) || ! (*alt_names)) {
+                       smb_panic_fn("trusted_domains out of memory");
+                       centry_free(centry);
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               (*names) = NULL;
+               (*alt_names) = NULL;
+               (*dom_sids) = NULL;
+       }
  
        for (i=0; i<(*num_domains); i++) {
                (*names)[i] = centry_string(centry, mem_ctx);
index 04d8f588845478163177423f0f0c94f6a8ab2bb5..e8b0ae641f75167f83d8f0617796555565a912a6 100644 (file)
@@ -402,13 +402,19 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
                return nt_status;
        }
 
-       *names = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
-       *alt_names = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
-       *dom_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_domains);
+       if (*num_domains) {
+               *names = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
+               *alt_names = TALLOC_ARRAY(mem_ctx, char *, *num_domains);
+               *dom_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_domains);
 
-       if ((*alt_names == NULL) || (*names == NULL) || (*dom_sids == NULL)) {
-               TALLOC_FREE(tmp_ctx);
-               return NT_STATUS_NO_MEMORY;
+               if ((*alt_names == NULL) || (*names == NULL) || (*dom_sids == NULL)) {
+                       TALLOC_FREE(tmp_ctx);
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               *names = NULL;
+               *alt_names = NULL;
+               *dom_sids = NULL;
        }
 
        for (i=0; i<*num_domains; i++) {
index 3707f0311f83c0994cf26b9051adc9b5907f3a6c..44326764149199e57290a12be6bc2c3124f727a3 100644 (file)
@@ -342,9 +342,13 @@ NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
 
        DEBUG(3, ("rids_to_names [rpc] for domain %s\n", domain->name ));
 
-       sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_rids);
-       if (sids == NULL) {
-               return NT_STATUS_NO_MEMORY;
+       if (num_rids) {
+               sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_rids);
+               if (sids == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               sids = NULL;
        }
 
        for (i=0; i<num_rids; i++) {
@@ -560,10 +564,13 @@ NTSTATUS msrpc_lookup_useraliases(struct winbindd_domain *domain,
                DEBUG(10,("rpc: lookup_useraliases: entering query %d for %d sids\n", 
                        num_queries, num_query_sids));  
 
-
-               query_sids = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_query_sids);
-               if (query_sids == NULL) {
-                       return NT_STATUS_NO_MEMORY;
+               if (num_query_sids) {
+                       query_sids = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_query_sids);
+                       if (query_sids == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               } else {
+                       query_sids = NULL;
                }
 
                for (i=0; i<num_query_sids; i++) {
index b260d8ce571cd35d133030907de493e3a00b995d..2cef17725b8778a6a5857dccb1d782f314d9d17c 100644 (file)
@@ -446,11 +446,16 @@ static BOOL lookup_rids(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid,
 {
        int i;
 
-       *names = TALLOC_ARRAY(mem_ctx, const char *, num_rids);
-       *types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_rids);
+       if (num_rids) {
+               *names = TALLOC_ARRAY(mem_ctx, const char *, num_rids);
+               *types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_rids);
 
-       if ((*names == NULL) || (*types == NULL)) {
-               return False;
+               if ((*names == NULL) || (*types == NULL)) {
+                       return False;
+               }
+       } else {
+               *names = NULL;
+               *types = NULL;
        }
 
        if (sid_check_is_domain(domain_sid)) {
@@ -687,10 +692,19 @@ NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
                return NT_STATUS_NO_MEMORY;
        }
 
-       name_infos = TALLOC_ARRAY(mem_ctx, struct lsa_name_info, num_sids);
+       if (num_sids) {
+               name_infos = TALLOC_ARRAY(mem_ctx, struct lsa_name_info, num_sids);
+               if (name_infos == NULL) {
+                       result = NT_STATUS_NO_MEMORY;
+                       goto fail;
+               }
+       } else {
+               name_infos = NULL;
+       }
+
        dom_infos = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_dom_info,
                                      MAX_REF_DOMAINS);
-       if ((name_infos == NULL) || (dom_infos == NULL)) {
+       if (dom_infos == NULL) {
                result = NT_STATUS_NO_MEMORY;
                goto fail;
        }
@@ -824,9 +838,13 @@ NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
                        break;
                }
 
-               if (!(rids = TALLOC_ARRAY(tmp_ctx, uint32, dom->num_idxs))) {
-                       result = NT_STATUS_NO_MEMORY;
-                       goto fail;
+               if (dom->num_idxs) {
+                       if (!(rids = TALLOC_ARRAY(tmp_ctx, uint32, dom->num_idxs))) {
+                               result = NT_STATUS_NO_MEMORY;
+                               goto fail;
+                       }
+               } else {
+                       rids = NULL;
                }
 
                for (j=0; j<dom->num_idxs; j++) {
index e2aed5ce252c608df9d95bd4781052554b5586c4..744f7ae99077c4546b51a53e0950ed222a66f5d9 100644 (file)
@@ -537,9 +537,13 @@ BOOL print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx, size_t
 
        num_pids = data.dsize / 8;
 
-       if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
-               ret = False;
-               goto done;
+       if (num_pids) {
+               if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
+                       ret = False;
+                       goto done;
+               }
+       } else {
+               pid_list = NULL;
        }
 
        for( i = 0, offset = 0; offset < data.dsize; offset += 8, i++)
index f2e95da8898025cb7f39ae6b750ca98e5e020f22..f7ea58f8a35635743caab293f05c782323d11765 100644 (file)
@@ -1847,8 +1847,12 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                }
                nk->values_off = prs_offset( &vlist_hbin->ps ) + vlist_hbin->first_hbin_off - HBIN_HDR_SIZE;
        
-               if ( !(nk->values = TALLOC_ARRAY( file->mem_ctx, REGF_VK_REC, nk->num_values )) )
-                       return NULL;
+               if (nk->num_values) {
+                       if ( !(nk->values = TALLOC_ARRAY( file->mem_ctx, REGF_VK_REC, nk->num_values )) )
+                               return NULL;
+               } else {
+                       nk->values = NULL;
+               }
 
                /* create the vk records */
 
index c01a55196606a329ddcd5d50e981df2fcbc86e93..5443170d8b2e1d2ee200095aca7e9a931ed59844 100644 (file)
@@ -98,10 +98,14 @@ NTSTATUS rpccli_ds_enum_domain_trusts(struct rpc_pipe_client *cli,
                int i;
        
                *num_domains = r.num_domains;
-               *trusts = TALLOC_ARRAY(mem_ctx, struct ds_domain_trust, r.num_domains);
+               if (r.num_domains) {
+                       *trusts = TALLOC_ARRAY(mem_ctx, struct ds_domain_trust, r.num_domains);
 
-               if (*trusts == NULL) {
-                       return NT_STATUS_NO_MEMORY;
+                       if (*trusts == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               } else {
+                       *trusts = NULL;
                }
 
                for ( i=0; i< *num_domains; i++ ) {
index 1f6daa17215f68b58a3ecb8b2e0ff8b1b4bda5ec..00b91e4a3c297654e7e7d624f0e39d77449427d5 100644 (file)
@@ -179,22 +179,28 @@ NTSTATUS rpccli_lsa_lookup_sids(struct rpc_pipe_client *cli,
                goto done;
        }
 
-       if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
-               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
-       }
+       if (num_sids) {
+               if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
+                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
 
-       if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
-               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
-       }
+               if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
+                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
 
-       if (!((*types) = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_sids))) {
-               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
+               if (!((*types) = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_sids))) {
+                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
+       } else {
+               (*domains) = NULL;
+               (*names) = NULL;
+               (*types) = NULL;
        }
                
        for (i = 0; i < num_sids; i++) {
@@ -281,25 +287,33 @@ NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
                goto done;
        }
 
-       if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
-               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
-       }
-
-       if (!((*types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_names)))) {
-               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
-       }
+       if (num_names) {
+               if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
+                       DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
 
-       if (dom_names != NULL) {
-               *dom_names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
-               if (*dom_names == NULL) {
+               if (!((*types = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_names)))) {
                        DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
                        result = NT_STATUS_NO_MEMORY;
                        goto done;
                }
+
+               if (dom_names != NULL) {
+                       *dom_names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
+                       if (*dom_names == NULL) {
+                               DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
+                               result = NT_STATUS_NO_MEMORY;
+                               goto done;
+                       }
+               }
+       } else {
+               *sids = NULL;
+               *types = NULL;
+               if (dom_names != NULL) {
+                       *dom_names = NULL;
+               }
        }
 
        for (i = 0; i < num_names; i++) {
@@ -744,22 +758,28 @@ NTSTATUS rpccli_lsa_enum_privilege(struct rpc_pipe_client *cli, TALLOC_CTX *mem_
        *enum_context = r.enum_context;
        *count = r.count;
 
-       if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
-               DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
-               result = NT_STATUS_UNSUCCESSFUL;
-               goto done;
-       }
+       if (r.count) {
+               if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
+                       DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
+                       result = NT_STATUS_UNSUCCESSFUL;
+                       goto done;
+               }
 
-       if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
-               DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
-               result = NT_STATUS_UNSUCCESSFUL;
-               goto done;
-       }
+               if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
+                       DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
+                       result = NT_STATUS_UNSUCCESSFUL;
+                       goto done;
+               }
 
-       if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
-               DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
-               result = NT_STATUS_UNSUCCESSFUL;
-               goto done;
+               if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
+                       DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
+                       result = NT_STATUS_UNSUCCESSFUL;
+                       goto done;
+               }
+       } else {
+               *privs_name = NULL;
+               *privs_high = NULL;
+               *privs_low = NULL;
        }
 
        for (i = 0; i < r.count; i++) {
index 593b0f385ba87ae4c3944dd49138b8f72640aba6..462add43819ed038683ed74dbb2aee717e3246a6 100644 (file)
@@ -536,10 +536,14 @@ NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli,
        ZERO_STRUCT(q);
        ZERO_STRUCT(r);
 
-       sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
-       if (sid_ptrs == NULL)
-               return NT_STATUS_NO_MEMORY;
-
+       if (num_sids) {
+               sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids);
+               if (sid_ptrs == NULL)
+                       return NT_STATUS_NO_MEMORY;
+       } else {
+               sid_ptrs = NULL;
+       }
+       
        for (i=0; i<num_sids; i++)
                sid_ptrs[i] = 1;
 
index 2d40f5dba1a00a795a8279d6e48490ed068baca6..76a5e0b8ad48423960e689bb4bdf6e67dc0b6dcd 100644 (file)
@@ -39,11 +39,15 @@ static BOOL decode_printer_info_0(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PRINTER_INFO_0  *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -66,11 +70,15 @@ static BOOL decode_printer_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PRINTER_INFO_1  *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -93,11 +101,15 @@ static BOOL decode_printer_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PRINTER_INFO_2  *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -122,11 +134,15 @@ static BOOL decode_printer_info_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PRINTER_INFO_3  *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -150,11 +166,15 @@ static BOOL decode_printer_info_7(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PRINTER_INFO_7  *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -178,11 +198,15 @@ static BOOL decode_port_info_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PORT_INFO_1 *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PORT_INFO_1));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PORT_INFO_1));
 
        prs_set_offset(&buffer->prs, 0);
 
@@ -205,11 +229,15 @@ static BOOL decode_port_info_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        PORT_INFO_2 *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(PORT_INFO_2));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(PORT_INFO_2));
 
        prs_set_offset(&buffer->prs, 0);
 
@@ -232,11 +260,15 @@ static BOOL decode_printer_driver_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        DRIVER_INFO_1 *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -259,11 +291,15 @@ static BOOL decode_printer_driver_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        DRIVER_INFO_2 *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -286,11 +322,15 @@ static BOOL decode_printer_driver_3(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
        uint32 i;
        DRIVER_INFO_3 *inf;
 
-       inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
-       if (!inf) {
-               return False;
+       if (returned) {
+               inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
+               if (!inf) {
+                       return False;
+               }
+               memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
+       } else {
+               inf = NULL;
        }
-       memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
 
        prs_set_offset(&buffer->prs,0);
 
@@ -337,9 +377,13 @@ static BOOL decode_jobs_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
 {
        uint32 i;
 
-       *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
-       if (*jobs == NULL) {
-               return False;
+       if (num_jobs) {
+               *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
+               if (*jobs == NULL) {
+                       return False;
+               }
+       } else {
+               *jobs = NULL;
        }
        prs_set_offset(&buffer->prs,0);
 
@@ -360,9 +404,13 @@ static BOOL decode_jobs_2(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
 {
        uint32 i;
 
-       *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
-       if (*jobs == NULL) {
-               return False;
+       if (num_jobs) {
+               *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
+               if (*jobs == NULL) {
+                       return False;
+               }
+       } else {
+               *jobs = NULL;
        }
        prs_set_offset(&buffer->prs,0);
 
@@ -383,10 +431,15 @@ static BOOL decode_forms_1(TALLOC_CTX *mem_ctx, RPC_BUFFER *buffer,
 {
        int i;
 
-       *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
-       if (*forms == NULL) {
-               return False;
+       if (num_forms) {
+               *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
+               if (*forms == NULL) {
+                       return False;
+               }
+       } else {
+               *forms = NULL;
        }
+
        prs_set_offset(&buffer->prs,0);
 
        for (i = 0; i < num_forms; i++) {
index bba2a51ad90aa8e928cc68e0dabf7e857c0e0aeb..3785fdd5f4b5f8e7e6c6b7ebd624b59ec344dc25 100644 (file)
@@ -700,9 +700,13 @@ static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
                }
        }
 
-       sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
-       if (sid2 == NULL)
-               return NT_STATUS_NO_MEMORY;
+       if (num_sids) {
+               sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
+               if (sid2 == NULL)
+                       return NT_STATUS_NO_MEMORY;
+       } else {
+               sid2 = NULL;
+       }
 
        for (i=0; i<num_sids; i++) {
                sid_copy(&sid2[i].sid, &sids[i]);
@@ -1795,11 +1799,15 @@ static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
        /* Look up names */
 
        num_names = argc - 2;
-       if ((names = TALLOC_ARRAY(mem_ctx, const char *, num_names)) == NULL) {
-               rpccli_samr_close(cli, mem_ctx, &domain_pol);
-               rpccli_samr_close(cli, mem_ctx, &connect_pol);
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
+       if (num_names) {
+               if ((names = TALLOC_ARRAY(mem_ctx, const char *, num_names)) == NULL) {
+                       rpccli_samr_close(cli, mem_ctx, &domain_pol);
+                       rpccli_samr_close(cli, mem_ctx, &connect_pol);
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
+       } else {
+               names = NULL;
        }
 
        for (i = 0; i < argc - 2; i++)
@@ -1866,12 +1874,15 @@ static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
        /* Look up rids */
 
        num_rids = argc - 2;
-       rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
-       if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
-               rpccli_samr_close(cli, mem_ctx, &domain_pol);
-               rpccli_samr_close(cli, mem_ctx, &connect_pol);
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
+       if (num_rids) {
+               if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
+                       rpccli_samr_close(cli, mem_ctx, &domain_pol);
+                       rpccli_samr_close(cli, mem_ctx, &connect_pol);
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
+       } else {
+               rids = NULL;
        }
 
        for (i = 0; i < argc - 2; i++)