summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/rpc_parse/parse_lsa.c47
-rw-r--r--source3/rpc_parse/parse_misc.c95
-rw-r--r--source3/rpc_parse/parse_net.c20
-rw-r--r--source3/rpc_parse/parse_samr.c32
4 files changed, 125 insertions, 69 deletions
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index cbbba7f3e9..ea249dc560 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.c
@@ -740,9 +740,13 @@ static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *p
return False;
if (UNMARSHALLING(ps)) {
- d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
- if (!d_q->auditsettings) {
- return False;
+ if (d_q->count2) {
+ d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
+ if (!d_q->auditsettings) {
+ return False;
+ }
+ } else {
+ d_q->auditsettings = NULL;
}
}
@@ -1121,16 +1125,16 @@ static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen,
/* Allocate memory for sids and sid pointers */
- if (num_entries == 0) return;
-
- if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
- DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
- return;
- }
+ if (num_entries) {
+ if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
+ DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
+ return;
+ }
- if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
- DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
- return;
+ if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
+ DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
+ return;
+ }
}
/* Copy across SIDs and SID pointers */
@@ -1566,14 +1570,19 @@ void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l,
q_l->num_entries2 = num_names;
q_l->lookup_level = 1;
- if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
- DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
- return;
- }
+ if (num_names) {
+ if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
+ DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
+ return;
+ }
- if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
- DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
- return;
+ if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
+ DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
+ return;
+ }
+ } else {
+ q_l->uni_name = NULL;
+ q_l->hdr_name = NULL;
}
for (i = 0; i < num_names; i++) {
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index a42915aa08..7a07ef5e7b 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -449,11 +449,15 @@ void init_unistr(UNISTR *str, const char *buf)
len = strlen(buf) + 1;
- str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
- if (str->buffer == NULL)
- smb_panic("init_unistr: malloc fail\n");
+ if (len) {
+ str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ if (str->buffer == NULL)
+ smb_panic("init_unistr: malloc fail\n");
- rpcstr_push(str->buffer, buf, len*sizeof(uint16), STR_TERMINATE);
+ rpcstr_push(str->buffer, buf, len*sizeof(uint16), STR_TERMINATE);
+ } else {
+ str->buffer = NULL;
+ }
}
/*******************************************************************
@@ -656,15 +660,18 @@ void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
(the the length of the source string) to prevent
reallocation of memory. */
if (str->buffer == NULL) {
- str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_max_len);
- if ((str->buffer == NULL)) {
- smb_panic("copy_unistr2: talloc fail\n");
- return;
+ if (str->uni_max_len) {
+ str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_max_len);
+ if ((str->buffer == NULL)) {
+ smb_panic("copy_unistr2: talloc fail\n");
+ return;
+ }
+ /* copy the string */
+ memcpy(str->buffer, from->buffer, str->uni_max_len*sizeof(uint16));
+ } else {
+ str->buffer = NULL;
}
}
-
- /* copy the string */
- memcpy(str->buffer, from->buffer, str->uni_max_len*sizeof(uint16));
}
/*******************************************************************
@@ -752,7 +759,9 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
len = strlen(buf) + 1;
if ( flags == UNI_STR_DBLTERMINATE )
len++;
- } else {
+ }
+
+ if (buf == NULL || len == 0) {
/* no buffer -- nothing to do */
str->uni_max_len = 0;
str->offset = 0;
@@ -840,10 +849,14 @@ void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
str->offset = 0;
str->uni_str_len = len;
- str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1);
- if (str->buffer == NULL) {
- smb_panic("init_unistr2_w: talloc fail\n");
- return;
+ if (len + 1) {
+ str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1);
+ if (str->buffer == NULL) {
+ smb_panic("init_unistr2_w: talloc fail\n");
+ return;
+ }
+ } else {
+ str->buffer = NULL;
}
/*
@@ -856,7 +869,9 @@ void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
/* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
long as the buffer above is talloc()ed correctly then this
is the correct thing to do */
- strncpy_w(str->buffer, buf, len + 1);
+ if (len+1) {
+ strncpy_w(str->buffer, buf, len + 1);
+ }
}
/*******************************************************************
@@ -890,10 +905,14 @@ void init_unistr2_from_unistr(UNISTR2 *to, const UNISTR *from)
to->uni_str_len = i;
/* allocate the space and copy the string buffer */
- to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);
- if (to->buffer == NULL)
- smb_panic("init_unistr2_from_unistr: malloc fail\n");
- memcpy(to->buffer, from->buffer, i*sizeof(uint16));
+ if (i) {
+ to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);
+ if (to->buffer == NULL)
+ smb_panic("init_unistr2_from_unistr: malloc fail\n");
+ memcpy(to->buffer, from->buffer, i*sizeof(uint16));
+ } else {
+ to->buffer = NULL;
+ }
return;
}
@@ -1089,12 +1108,13 @@ BOOL prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRA
if(!prs_uint32("count", ps, depth, &array->count))
return False;
- if ( array->count == 0 )
- return True;
-
if (UNMARSHALLING(ps)) {
- if ( !(array->strings = TALLOC_ZERO_ARRAY( get_talloc_ctx(), UNISTR4, array->count)) )
- return False;
+ if (array->count) {
+ if ( !(array->strings = TALLOC_ZERO_ARRAY( get_talloc_ctx(), UNISTR4, array->count)) )
+ return False;
+ } else {
+ array->strings = NULL;
+ }
}
/* write the headers and then the actual string buffer */
@@ -1122,13 +1142,14 @@ BOOL init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **string
array->count = count;
- if ( array->count == 0 )
- return True;
-
/* allocate memory for the array of UNISTR4 objects */
- if ( !(array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR4, count )) )
- return False;
+ if (array->count) {
+ if ( !(array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR4, count )) )
+ return False;
+ } else {
+ array->strings = NULL;
+ }
for ( i=0; i<count; i++ )
init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE );
@@ -1677,11 +1698,15 @@ void init_unistr3(UNISTR3 *str, const char *buf)
str->uni_str_len = strlen(buf) + 1;
- str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_str_len);
- if (str->str.buffer == NULL)
- smb_panic("init_unistr3: malloc fail\n");
+ if (str->uni_str_len) {
+ str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_str_len);
+ if (str->str.buffer == NULL)
+ smb_panic("init_unistr3: malloc fail\n");
- rpcstr_push((char *)str->str.buffer, buf, str->uni_str_len * sizeof(uint16), STR_TERMINATE);
+ rpcstr_push((char *)str->str.buffer, buf, str->uni_str_len * sizeof(uint16), STR_TERMINATE);
+ } else {
+ str->str.buffer = NULL;
+ }
}
/*******************************************************************
diff --git a/source3/rpc_parse/parse_net.c b/source3/rpc_parse/parse_net.c
index d821cf85f0..4c2f676831 100644
--- a/source3/rpc_parse/parse_net.c
+++ b/source3/rpc_parse/parse_net.c
@@ -1106,9 +1106,13 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
}
/* Now allocate space for them. */
- *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
- if (*ppsids == NULL)
- return 0;
+ if (count) {
+ *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
+ if (*ppsids == NULL)
+ return 0;
+ } else {
+ *ppsids = NULL;
+ }
sids = *ppsids;
@@ -1590,9 +1594,13 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
usr->num_groups2 = num_groups;
- usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
- if (usr->gids == NULL && num_groups>0)
- return;
+ if (num_groups) {
+ usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
+ if (usr->gids == NULL)
+ return;
+ } else {
+ usr->gids = NULL;
+ }
for (i = 0; i < num_groups; i++)
usr->gids[i] = gids[i];
diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c
index 9beefbc0c0..49a1db75c0 100644
--- a/source3/rpc_parse/parse_samr.c
+++ b/source3/rpc_parse/parse_samr.c
@@ -4245,7 +4245,11 @@ void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
q_u->flags = flags;
q_u->ptr = 0;
q_u->num_rids2 = num_rids;
- q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
+ if (num_rids) {
+ q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
+ } else {
+ q_u->rid = NULL;
+ }
if (q_u->rid == NULL) {
q_u->num_rids1 = 0;
q_u->num_rids2 = 0;
@@ -4897,11 +4901,16 @@ NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
q_u->ptr = 0;
q_u->num_names2 = num_names;
- if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
- return NT_STATUS_NO_MEMORY;
+ if (num_names) {
+ if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
+ return NT_STATUS_NO_MEMORY;
- if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
- return NT_STATUS_NO_MEMORY;
+ if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
+ return NT_STATUS_NO_MEMORY;
+ } else {
+ q_u->hdr_name = NULL;
+ q_u->uni_name = NULL;
+ }
for (i = 0; i < num_names; i++) {
init_unistr2(&q_u->uni_name[i], name[i], UNI_FLAGS_NONE); /* unicode string for machine account */
@@ -4986,10 +4995,15 @@ NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
r_u->ptr_rids = 1;
r_u->num_rids2 = num_rids;
- if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
- return NT_STATUS_NO_MEMORY;
- if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
- return NT_STATUS_NO_MEMORY;
+ if (num_rids) {
+ if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
+ return NT_STATUS_NO_MEMORY;
+ if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
+ return NT_STATUS_NO_MEMORY;
+ } else {
+ r_u->rids = NULL;
+ r_u->types = NULL;
+ }
if (!r_u->rids || !r_u->types)
goto empty;