summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-04-30 02:39:34 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:19:49 -0500
commitbe8b0685a55700c6bce3681734800ec6434b0364 (patch)
tree8616d85686fb147d431eeea435233f45d5ee8d41
parent79de0ad9463a5cd64978beae37df79fbb4f74632 (diff)
downloadsamba-be8b0685a55700c6bce3681734800ec6434b0364.tar.gz
samba-be8b0685a55700c6bce3681734800ec6434b0364.tar.bz2
samba-be8b0685a55700c6bce3681734800ec6434b0364.zip
r22589: Make TALLOC_ARRAY consistent across all uses.
Jeremy. (This used to be commit 8968808c3b5b0208cbad9ac92eaf948f2c546dd9)
-rw-r--r--source3/auth/auth_util.c14
-rw-r--r--source3/lib/privileges.c12
-rw-r--r--source3/lib/secdesc.c8
-rw-r--r--source3/libaddns/dnsrecord.c10
-rw-r--r--source3/libaddns/dnssock.c10
-rw-r--r--source3/libads/dns.c22
-rw-r--r--source3/libads/ldap.c12
-rw-r--r--source3/libmsrpc/cac_lsarpc.c89
-rw-r--r--source3/libmsrpc/cac_samr.c140
-rw-r--r--source3/libmsrpc/libmsrpc_internal.c14
-rw-r--r--source3/libsmb/clifile.c10
-rw-r--r--source3/modules/vfs_afsacl.c10
-rw-r--r--source3/nsswitch/wb_client.c13
-rw-r--r--source3/nsswitch/winbindd_cache.c34
-rw-r--r--source3/nsswitch/winbindd_passdb.c18
-rw-r--r--source3/nsswitch/winbindd_rpc.c21
-rw-r--r--source3/passdb/lookup_sid.c36
-rw-r--r--source3/printing/notify.c10
-rw-r--r--source3/registry/regfio.c8
-rw-r--r--source3/rpc_client/cli_ds.c10
-rw-r--r--source3/rpc_client/cli_lsarpc.c104
-rw-r--r--source3/rpc_client/cli_samr.c12
-rw-r--r--source3/rpc_client/cli_spoolss.c151
-rw-r--r--source3/rpcclient/cmd_samr.c39
24 files changed, 522 insertions, 285 deletions
diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c
index e2bc8e75b5..db92c50df0 100644
--- a/source3/auth/auth_util.c
+++ b/source3/auth/auth_util.c
@@ -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++) {
diff --git a/source3/lib/privileges.c b/source3/lib/privileges.c
index 5fa9fd7a7d..cd6494d1ed 100644
--- a/source3/lib/privileges.c
+++ b/source3/lib/privileges.c
@@ -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++) {
diff --git a/source3/lib/secdesc.c b/source3/lib/secdesc.c
index 762dc2f6d8..510282bbfb 100644
--- a/source3/lib/secdesc.c
+++ b/source3/lib/secdesc.c
@@ -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];
diff --git a/source3/libaddns/dnsrecord.c b/source3/libaddns/dnsrecord.c
index 37a5886af7..c649dbd7de 100644
--- a/source3/libaddns/dnsrecord.c
+++ b/source3/libaddns/dnsrecord.c
@@ -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);
diff --git a/source3/libaddns/dnssock.c b/source3/libaddns/dnssock.c
index 5dbedc4fd5..6ceefb4e32 100644
--- a/source3/libaddns/dnssock.c
+++ b/source3/libaddns/dnssock.c
@@ -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);
diff --git a/source3/libads/dns.c b/source3/libads/dns.c
index 008266ea0b..8b031b0e3a 100644
--- a/source3/libads/dns.c
+++ b/source3/libads/dns.c
@@ -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 */
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index 6707cbd4d0..5a34385c32 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -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;
diff --git a/source3/libmsrpc/cac_lsarpc.c b/source3/libmsrpc/cac_lsarpc.c
index 2e3eb276d5..de53c0f483 100644
--- a/source3/libmsrpc/cac_lsarpc.c
+++ b/source3/libmsrpc/cac_lsarpc.c
@@ -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;
diff --git a/source3/libmsrpc/cac_samr.c b/source3/libmsrpc/cac_samr.c
index e50fb474f5..4d3acc85e3 100644
--- a/source3/libmsrpc/cac_samr.c
+++ b/source3/libmsrpc/cac_samr.c
@@ -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++ ) {
diff --git a/source3/libmsrpc/libmsrpc_internal.c b/source3/libmsrpc/libmsrpc_internal.c
index 64e6332e80..3cb702e376 100644
--- a/source3/libmsrpc/libmsrpc_internal.c
+++ b/source3/libmsrpc/libmsrpc_internal.c
@@ -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 */
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index ad6029f224..2e1c156f14 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -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);
diff --git a/source3/modules/vfs_afsacl.c b/source3/modules/vfs_afsacl.c
index 43fa537d73..a82e6b350b 100644
--- a/source3/modules/vfs_afsacl.c
+++ b/source3/modules/vfs_afsacl.c
@@ -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;
diff --git a/source3/nsswitch/wb_client.c b/source3/nsswitch/wb_client.c
index afb6202754..25fbefc45e 100644
--- a/source3/nsswitch/wb_client.c
+++ b/source3/nsswitch/wb_client.c
@@ -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;
diff --git a/source3/nsswitch/winbindd_cache.c b/source3/nsswitch/winbindd_cache.c
index da8983dda2..47bd872f03 100644
--- a/source3/nsswitch/winbindd_cache.c
+++ b/source3/nsswitch/winbindd_cache.c
@@ -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);
diff --git a/source3/nsswitch/winbindd_passdb.c b/source3/nsswitch/winbindd_passdb.c
index 04d8f58884..e8b0ae641f 100644
--- a/source3/nsswitch/winbindd_passdb.c
+++ b/source3/nsswitch/winbindd_passdb.c
@@ -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++) {
diff --git a/source3/nsswitch/winbindd_rpc.c b/source3/nsswitch/winbindd_rpc.c
index 3707f0311f..4432676414 100644
--- a/source3/nsswitch/winbindd_rpc.c
+++ b/source3/nsswitch/winbindd_rpc.c
@@ -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++) {
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
index b260d8ce57..2cef17725b 100644
--- a/source3/passdb/lookup_sid.c
+++ b/source3/passdb/lookup_sid.c
@@ -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++) {
diff --git a/source3/printing/notify.c b/source3/printing/notify.c
index e2aed5ce25..744f7ae990 100644
--- a/source3/printing/notify.c
+++ b/source3/printing/notify.c
@@ -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++)
diff --git a/source3/registry/regfio.c b/source3/registry/regfio.c
index f2e95da889..f7ea58f8a3 100644
--- a/source3/registry/regfio.c
+++ b/source3/registry/regfio.c
@@ -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 */
diff --git a/source3/rpc_client/cli_ds.c b/source3/rpc_client/cli_ds.c
index c01a551966..5443170d8b 100644
--- a/source3/rpc_client/cli_ds.c
+++ b/source3/rpc_client/cli_ds.c
@@ -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++ ) {
diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c
index 1f6daa1721..00b91e4a3c 100644
--- a/source3/rpc_client/cli_lsarpc.c
+++ b/source3/rpc_client/cli_lsarpc.c
@@ -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++) {
diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c
index 593b0f385b..462add4381 100644
--- a/source3/rpc_client/cli_samr.c
+++ b/source3/rpc_client/cli_samr.c
@@ -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;
diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c
index 2d40f5dba1..76a5e0b8ad 100644
--- a/source3/rpc_client/cli_spoolss.c
+++ b/source3/rpc_client/cli_spoolss.c
@@ -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++) {
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index bba2a51ad9..3785fdd5f4 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -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++)