1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-04 16:58:42 +03:00

r22589: Make TALLOC_ARRAY consistent across all uses.

Jeremy.
(This used to be commit 8968808c3b5b0208cbad9ac92eaf948f2c546dd9)
This commit is contained in:
Jeremy Allison 2007-04-30 02:39:34 +00:00 committed by Gerald (Jerry) Carter
parent 79de0ad946
commit be8b0685a5
24 changed files with 523 additions and 286 deletions

View 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++) {

View 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++) {

View 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];

View 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);

View 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);

View 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 */

View 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;

View 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;

View 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++ ) {

View 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 */

View 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);

View 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;

View 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;

View 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);

View 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++) {

View 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++) {

View 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++) {

View 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++)

View 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 */

View 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++ ) {

View 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 (dom_names != NULL) {
*dom_names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
if (*dom_names == NULL) {
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 (!((*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++) {

View 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;

View 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++) {

View 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++)