summaryrefslogtreecommitdiff
path: root/source3/rpc_parse
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-12-07 18:25:53 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:53:32 -0500
commitacf9d61421faa6c0055d57fdee7db300dc5431aa (patch)
tree5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/rpc_parse
parent3bd3be97dc8a581c0502410453091c195e322766 (diff)
downloadsamba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.gz
samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.bz2
samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.zip
r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a)
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r--source3/rpc_parse/parse_dfs.c8
-rw-r--r--source3/rpc_parse/parse_ds.c4
-rw-r--r--source3/rpc_parse/parse_echo.c8
-rw-r--r--source3/rpc_parse/parse_lsa.c58
-rw-r--r--source3/rpc_parse/parse_misc.c80
-rw-r--r--source3/rpc_parse/parse_net.c49
-rw-r--r--source3/rpc_parse/parse_prs.c37
-rw-r--r--source3/rpc_parse/parse_samr.c150
-rw-r--r--source3/rpc_parse/parse_sec.c12
-rw-r--r--source3/rpc_parse/parse_spoolss.c105
-rw-r--r--source3/rpc_parse/parse_srv.c34
11 files changed, 239 insertions, 306 deletions
diff --git a/source3/rpc_parse/parse_dfs.c b/source3/rpc_parse/parse_dfs.c
index 0d0ce557b2..3f7b2a4cd5 100644
--- a/source3/rpc_parse/parse_dfs.c
+++ b/source3/rpc_parse/parse_dfs.c
@@ -374,7 +374,7 @@ BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries
depth++;
/* should depend on whether marshalling or unmarshalling! */
if(UNMARSHALLING(ps)) {
- ctr->dfs.info1 = (DFS_INFO_1 *)prs_alloc_mem(ps, sizeof(DFS_INFO_1)*num_entries);
+ ctr->dfs.info1 = PRS_ALLOC_MEM(ps, DFS_INFO_1, num_entries);
if (!ctr->dfs.info1)
return False;
}
@@ -394,7 +394,7 @@ BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries
case 2:
depth++;
if(UNMARSHALLING(ps)) {
- ctr->dfs.info2 = (DFS_INFO_2 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_2));
+ ctr->dfs.info2 = PRS_ALLOC_MEM(ps, DFS_INFO_2, num_entries);
if (!ctr->dfs.info2)
return False;
}
@@ -424,7 +424,7 @@ BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries
case 3:
depth++;
if(UNMARSHALLING(ps)) {
- ctr->dfs.info3 = (DFS_INFO_3 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_3));
+ ctr->dfs.info3 = PRS_ALLOC_MEM(ps, DFS_INFO_3, num_entries);
if (!ctr->dfs.info3)
return False;
}
@@ -517,7 +517,7 @@ BOOL dfs_io_dfs_storage_info(const char *desc, DFS_INFO_3* info3, prs_struct *ps
depth++;
if(UNMARSHALLING(ps)) {
- info3->storages = (DFS_STORAGE_INFO *)prs_alloc_mem(ps, info3->num_storage_infos*sizeof(DFS_STORAGE_INFO));
+ info3->storages = PRS_ALLOC_MEM(ps, DFS_STORAGE_INFO, info3->num_storage_infos);
if (!info3->storages)
return False;
}
diff --git a/source3/rpc_parse/parse_ds.c b/source3/rpc_parse/parse_ds.c
index 070f6be43a..9155419ae4 100644
--- a/source3/rpc_parse/parse_ds.c
+++ b/source3/rpc_parse/parse_ds.c
@@ -29,7 +29,7 @@ static BOOL ds_io_dominfobasic( const char *desc, prs_struct *ps, int depth, DSR
DSROLE_PRIMARY_DOMAIN_INFO_BASIC *p = *basic;
if ( UNMARSHALLING(ps) )
- p = *basic = (DSROLE_PRIMARY_DOMAIN_INFO_BASIC *)prs_alloc_mem(ps, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
+ p = *basic = PRS_ALLOC_MEM(ps, DSROLE_PRIMARY_DOMAIN_INFO_BASIC, 1);
if ( !p )
return False;
@@ -208,7 +208,7 @@ static BOOL ds_io_dom_trusts_ctr( const char *desc, prs_struct *ps, int depth, D
/* allocate the domain trusts array are parse it */
- ctr->trusts = (DS_DOMAIN_TRUSTS*)talloc(ps->mem_ctx, sizeof(DS_DOMAIN_TRUSTS)*ctr->max_count);
+ ctr->trusts = TALLOC_ARRAY(ps->mem_ctx, DS_DOMAIN_TRUSTS, ctr->max_count);
if ( !ctr->trusts )
return False;
diff --git a/source3/rpc_parse/parse_echo.c b/source3/rpc_parse/parse_echo.c
index 4b1ff1f4d5..b4aa8de24a 100644
--- a/source3/rpc_parse/parse_echo.c
+++ b/source3/rpc_parse/parse_echo.c
@@ -67,7 +67,7 @@ BOOL echo_io_q_echo_data(const char *desc, ECHO_Q_ECHO_DATA *q_d,
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
@@ -86,7 +86,7 @@ BOOL echo_io_r_echo_data(const char *desc, ECHO_R_ECHO_DATA *q_d,
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
@@ -114,7 +114,7 @@ BOOL echo_io_q_sink_data(const char *desc, ECHO_Q_SINK_DATA *q_d,
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
@@ -153,7 +153,7 @@ BOOL echo_io_r_source_data(const char *desc, ECHO_R_SOURCE_DATA *q_d,
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index 5fff1fea37..e2cb94c8fe 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.c
@@ -251,7 +251,7 @@ static BOOL lsa_io_obj_attr(const char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps
if (attr->ptr_sec_qos != 0) {
if (UNMARSHALLING(ps))
- if (!(attr->sec_qos = (LSA_SEC_QOS *)prs_alloc_mem(ps,sizeof(LSA_SEC_QOS))))
+ if (!(attr->sec_qos = PRS_ALLOC_MEM(ps,LSA_SEC_QOS,1)))
return False;
if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
@@ -540,17 +540,17 @@ void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 en
* allocating empty arrays of unicode headers, strings
* and sids of enumerated trusted domains
*/
- if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2) * num_domains))) {
+ if (!(r_e->hdr_domain_name = TALLOC_ARRAY(ctx,UNIHDR2,num_domains))) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
- if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2) * num_domains))) {
+ if (!(r_e->uni_domain_name = TALLOC_ARRAY(ctx,UNISTR2,num_domains))) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
- if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2) * num_domains))) {
+ if (!(r_e->domain_sid = TALLOC_ARRAY(ctx,DOM_SID2,num_domains))) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
@@ -596,13 +596,13 @@ BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *r_e,
num_domains = r_e->num_domains2;
if (UNMARSHALLING(ps)) {
- if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
+ if (!(r_e->hdr_domain_name = PRS_ALLOC_MEM(ps,UNIHDR2,num_domains)))
return False;
- if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
+ if (!(r_e->uni_domain_name = PRS_ALLOC_MEM(ps,UNISTR2,num_domains)))
return False;
- if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
+ if (!(r_e->domain_sid = PRS_ALLOC_MEM(ps,DOM_SID2,num_domains)))
return False;
}
@@ -697,7 +697,7 @@ 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 = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32));
+ d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
}
if (d_q->auditsettings == NULL) {
@@ -818,14 +818,12 @@ static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen,
if (num_entries == 0) return;
- if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries *
- sizeof(uint32))) == NULL) {
+ 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 = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries *
- sizeof(DOM_SID2))) == NULL) {
+ 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;
}
@@ -872,15 +870,13 @@ static BOOL lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps,
/* Mallocate memory if we're unpacking from the wire */
if (UNMARSHALLING(ps)) {
- if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
- sen->num_entries * sizeof(uint32))) == NULL) {
+ if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
"ptr_sid\n"));
return False;
}
- if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
- sen->num_entries * sizeof(DOM_SID2))) == NULL) {
+ if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
"sids\n"));
return False;
@@ -980,15 +976,11 @@ static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
return False;
if (UNMARSHALLING(ps)) {
- if ((trn->name = (LSA_TRANS_NAME *)
- prs_alloc_mem(ps, trn->num_entries *
- sizeof(LSA_TRANS_NAME))) == NULL) {
+ if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
return False;
}
- if ((trn->uni_name = (UNISTR2 *)
- prs_alloc_mem(ps, trn->num_entries *
- sizeof(UNISTR2))) == NULL) {
+ if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
return False;
}
}
@@ -1068,14 +1060,12 @@ 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 = (UNISTR2 *)talloc_zero(
- mem_ctx, num_names * sizeof(UNISTR2))) == NULL) {
+ 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 = (UNIHDR *)talloc_zero(
- mem_ctx, num_names * sizeof(UNIHDR))) == NULL) {
+ 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;
}
@@ -1113,11 +1103,9 @@ BOOL lsa_io_q_lookup_names(const char *desc, LSA_Q_LOOKUP_NAMES *q_r,
if (UNMARSHALLING(ps)) {
if (q_r->num_entries) {
- if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
- q_r->num_entries * sizeof(UNIHDR))) == NULL)
+ if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
return False;
- if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
- q_r->num_entries * sizeof(UNISTR2))) == NULL)
+ if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
return False;
}
}
@@ -1187,7 +1175,7 @@ BOOL lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *r_r,
}
if (UNMARSHALLING(ps)) {
- if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
+ if ((r_r->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, r_r->num_entries2))
== NULL) {
DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
return False;
@@ -1409,7 +1397,7 @@ BOOL lsa_io_r_enum_privs(const char *desc, LSA_R_ENUM_PRIVS *r_q, prs_struct *ps
return False;
if (UNMARSHALLING(ps))
- if (!(r_q->privs = (LSA_PRIV_ENTRY *)prs_alloc_mem(ps, sizeof(LSA_PRIV_ENTRY) * r_q->count1)))
+ if (!(r_q->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, r_q->count1)))
return False;
if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
@@ -1852,7 +1840,7 @@ BOOL lsa_io_r_enum_privsaccount(const char *desc, LSA_R_ENUMPRIVSACCOUNT *r_c, p
if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
return False;
- if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
+ if (!(r_c->set->set = PRS_ALLOC_MEM(ps,LUID_ATTR,r_c->count)))
return False;
}
@@ -2022,7 +2010,7 @@ BOOL lsa_io_q_addprivs(const char *desc, LSA_Q_ADDPRIVS *r_c, prs_struct *ps, in
if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
return False;
- if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps, sizeof(LUID_ATTR) * r_c->count)))
+ if (!(r_c->set->set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
return False;
}
@@ -2084,7 +2072,7 @@ BOOL lsa_io_q_removeprivs(const char *desc, LSA_Q_REMOVEPRIVS *r_c, prs_struct *
if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
return False;
- if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps, sizeof(LUID_ATTR) * r_c->count)))
+ if (!(r_c->set->set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
return False;
}
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index c6f05df0c4..17a8f624ae 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -552,18 +552,14 @@ void init_unistr(UNISTR *str, const char *buf)
return;
}
-
len = strlen(buf) + 1;
+ len = MAX(len,MAX_UNISTRLEN);
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
- len *= sizeof(uint16);
-
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), 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, STR_TERMINATE);
+ rpcstr_push(str->buffer, buf, len*sizeof(uint16), STR_TERMINATE);
}
/*******************************************************************
@@ -591,10 +587,9 @@ BOOL smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth)
static void create_buffer3(BUFFER3 *str, size_t len)
{
- if (len < MAX_BUFFERLEN)
- len = MAX_BUFFERLEN;
+ len = MAX(len,MAX_BUFFERLEN);
- str->buffer = talloc_zero(get_talloc_ctx(), len);
+ str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
if (str->buffer == NULL)
smb_panic("create_buffer3: talloc fail\n");
@@ -683,7 +678,7 @@ BOOL smb_io_buffer3(const char *desc, BUFFER3 *buf3, prs_struct *ps, int depth)
return False;
if (UNMARSHALLING(ps)) {
- buf3->buffer = (unsigned char *)prs_alloc_mem(ps, buf3->buf_max_len);
+ buf3->buffer = PRS_ALLOC_MEM(ps, unsigned char, buf3->buf_max_len);
if (buf3->buffer == NULL)
return False;
}
@@ -735,9 +730,8 @@ void init_buffer2(BUFFER2 *str, const uint8 *buf, size_t len)
str->buf_len = buf != NULL ? len : 0;
if (buf != NULL) {
- if (len < MAX_BUFFERLEN)
- len = MAX_BUFFERLEN;
- str->buffer = talloc_zero(get_talloc_ctx(), len);
+ len = MAX(len,MAX_BUFFERLEN);
+ str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
if (str->buffer == NULL)
smb_panic("init_buffer2: talloc fail\n");
memcpy(str->buffer, buf, MIN(str->buf_len, len));
@@ -819,14 +813,9 @@ void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
(the the length of the source string) to prevent
reallocation of memory. */
if (str->buffer == NULL) {
- size_t len = from->uni_max_len * sizeof(uint16);
-
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
- len *= sizeof(uint16);
-
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
- if ((str->buffer == NULL) && (len > 0 )) {
+ size_t alloc_len = MAX(from->uni_max_len,MAX_UNISTRLEN);
+ str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
+ if ((str->buffer == NULL)) {
smb_panic("copy_unistr2: talloc fail\n");
return;
}
@@ -842,8 +831,6 @@ void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
{
- int alloc_len = 0;
-
/* set up string lengths. */
str->str_max_len = max_len;
str->offset = 0;
@@ -851,9 +838,8 @@ void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
/* store the string */
if(str_len != 0) {
- if (str_len < MAX_STRINGLEN)
- alloc_len = MAX_STRINGLEN;
- str->buffer = talloc_zero(get_talloc_ctx(), alloc_len);
+ int alloc_len = MAX(str_len, MAX_STRINGLEN);
+ str->buffer = TALLOC_ZERO(get_talloc_ctx(), alloc_len);
if (str->buffer == NULL)
smb_panic("init_string2: malloc fail\n");
memcpy(str->buffer, buf, str_len);
@@ -917,16 +903,17 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
len = strlen(buf) + 1;
}
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
- len *= sizeof(uint16);
+ len = MAX(len,MAX_UNISTRLEN);
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
- if ((str->buffer == NULL) && (len > 0)) {
+ str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ if (str->buffer == NULL) {
smb_panic("init_unistr2: malloc fail\n");
return;
}
+ /* Ensure len is the length in *bytes* */
+ len *= sizeof(uint16);
+
/*
* The UNISTR2 must be initialized !!!
* jfm, 7/7/2001.
@@ -956,7 +943,6 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
{
uint32 len = strlen_w(buf);
- uint32 max_len = len;
uint32 alloc_len;
ZERO_STRUCTP(str);
@@ -966,13 +952,10 @@ void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
str->offset = 0;
str->uni_str_len = len;
- if (max_len < MAX_UNISTRLEN)
- max_len = MAX_UNISTRLEN;
+ alloc_len = MAX((len + 1), MAX_UNISTRLEN);
- alloc_len = (max_len + 1) * sizeof(uint16);
-
- str->buffer = (uint16 *)talloc_zero(ctx, alloc_len);
- if ((str->buffer == NULL) && (alloc_len > 0)) {
+ str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, alloc_len);
+ if (str->buffer == NULL) {
smb_panic("init_unistr2_w: malloc fail\n");
return;
}
@@ -1021,10 +1004,10 @@ 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 = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len));
+ 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, to->uni_max_len*sizeof(uint16));
+ memcpy(to->buffer, from->buffer, i*sizeof(uint16));
return;
}
@@ -1111,7 +1094,7 @@ BOOL init_unistr2_array(UNISTR2_ARRAY *array,
return True;
}
- array->strings = (UNISTR2_ARRAY_EL *)talloc_zero(get_talloc_ctx(), count * sizeof(UNISTR2_ARRAY_EL));
+ array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR2_ARRAY_EL, count );
if (!array->strings) {
return False;
}
@@ -1151,7 +1134,7 @@ BOOL smb_io_unistr2_array(const char *desc, UNISTR2_ARRAY *array, prs_struct *ps
}
if (UNMARSHALLING(ps)) {
- array->strings = talloc_zero(get_talloc_ctx(), array->count * sizeof(array->strings[0]));
+ array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR2_ARRAY_EL, array->count );
}
if (! array->strings) {
return False;
@@ -1637,7 +1620,7 @@ BOOL smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth
void init_unistr3(UNISTR3 *str, const char *buf)
{
- size_t len;
+ size_t len, alloc_len;
if (buf == NULL) {
str->uni_str_len=0;
@@ -1649,16 +1632,13 @@ void init_unistr3(UNISTR3 *str, const char *buf)
str->uni_str_len=len;
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
-
- len *= sizeof(uint16);
+ alloc_len = MAX(len, MAX_UNISTRLEN);
- str->str.buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
+ str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
if (str->str.buffer == NULL)
smb_panic("init_unistr3: malloc fail\n");
- rpcstr_push((char *)str->str.buffer, buf, len, STR_TERMINATE);
+ rpcstr_push((char *)str->str.buffer, buf, len * sizeof(uint16), STR_TERMINATE);
}
/*******************************************************************
diff --git a/source3/rpc_parse/parse_net.c b/source3/rpc_parse/parse_net.c
index 813316177a..97ca0d406b 100644
--- a/source3/rpc_parse/parse_net.c
+++ b/source3/rpc_parse/parse_net.c
@@ -1019,7 +1019,7 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
}
/* Now allocate space for them. */
- *ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
+ *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
if (*ppsids == NULL)
return 0;
@@ -1310,7 +1310,7 @@ static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_s
depth++;
if (UNMARSHALLING(ps)) {
- ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
+ ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
if (ctr == NULL)
return False;
}
@@ -1481,7 +1481,7 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
usr->num_groups2 = num_groups;
- usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups));
+ usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
if (usr->gids == NULL && num_groups>0)
return;
@@ -1614,7 +1614,7 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
return False;
if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
- usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
+ usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups2);
if (usr->gids == NULL)
return False;
}
@@ -1635,7 +1635,7 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
if (usr->num_other_sids) {
if (UNMARSHALLING(ps)) {
- usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
+ usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
if (usr->other_sids == NULL)
return False;
}
@@ -1644,7 +1644,7 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
return False;
if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
- usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
+ usr->other_gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_other_groups);
if (usr->other_gids == NULL)
return False;
}
@@ -2322,8 +2322,7 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
return False;
}
- info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
- info->num_members2);
+ info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
if (info->rids == NULL) {
DEBUG(0, ("out of memory allocating %d rids\n",
@@ -2350,8 +2349,7 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
return False;
}
- info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
- info->num_members3);
+ info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
if (info->attribs == NULL) {
DEBUG(0, ("out of memory allocating %d attribs\n",
@@ -2438,8 +2436,7 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
return False;
}
- info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
- info->num_sids);
+ info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
if (info->ptr_sids == NULL) {
DEBUG(0, ("out of memory allocating %d ptr_sids\n",
@@ -2454,8 +2451,7 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
return False;
}
- info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
- info->num_sids);
+ info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
if (info->sids == NULL) {
DEBUG(0, ("error allocating %d sids\n",
@@ -2772,7 +2768,7 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
return False;
- info->attributes = talloc(ps->mem_ctx, sizeof(uint32) * info->attribute_count);
+ info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
for (i=0; i<info->attribute_count; i++)
if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
@@ -2781,8 +2777,8 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
return False;
- info->hdr_privslist = talloc(ps->mem_ctx, sizeof(UNIHDR) * info->privlist_count);
- info->uni_privslist = talloc(ps->mem_ctx, sizeof(UNISTR2) * info->privlist_count);
+ info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
+ info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
for (i=0; i<info->privlist_count; i++)
if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
@@ -2914,10 +2910,7 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
}
if (r_s->num_deltas2 > 0) {
- r_s->hdr_deltas = (SAM_DELTA_HDR *)
- talloc(ps->mem_ctx, r_s->num_deltas2 *
- sizeof(SAM_DELTA_HDR));
-
+ r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
if (r_s->hdr_deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d delta headers\n",
@@ -2935,10 +2928,7 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
}
if (r_s->num_deltas2 > 0) {
- r_s->deltas = (SAM_DELTA_CTR *)
- talloc(ps->mem_ctx, r_s->num_deltas2 *
- sizeof(SAM_DELTA_CTR));
-
+ r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
if (r_s->deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d deltas\n",
@@ -3050,9 +3040,7 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
if (r_s->ptr_deltas != 0)
{
if (r_s->num_deltas > 0) {
- r_s->hdr_deltas = (SAM_DELTA_HDR *)
- talloc(ps->mem_ctx, r_s->num_deltas *
- sizeof(SAM_DELTA_HDR));
+ r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
if (r_s->hdr_deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d delta headers\n",
@@ -3068,10 +3056,7 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
}
if (r_s->num_deltas > 0) {
- r_s->deltas = (SAM_DELTA_CTR *)
- talloc(ps->mem_ctx, r_s->num_deltas *
- sizeof(SAM_DELTA_CTR));
-
+ r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
if (r_s->deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d deltas\n",
diff --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c
index c70011c648..67a9d96e19 100644
--- a/source3/rpc_parse/parse_prs.c
+++ b/source3/rpc_parse/parse_prs.c
@@ -105,7 +105,7 @@ BOOL prs_init(prs_struct *ps, uint32 size, TALLOC_CTX *ctx, BOOL io)
if (size != 0) {
ps->buffer_size = size;
- if((ps->data_p = (char *)malloc((size_t)size)) == NULL) {
+ if((ps->data_p = (char *)SMB_MALLOC((size_t)size)) == NULL) {
DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
return False;
}
@@ -143,14 +143,21 @@ void prs_mem_clear(prs_struct *ps)
Allocate memory when unmarshalling... Always zero clears.
********************************************************************/
-char *prs_alloc_mem(prs_struct *ps, size_t size)
+#if defined(PARANOID_MALLOC_CHECKER)
+char *prs_alloc_mem_(prs_struct *ps, size_t size, unsigned int count)
+#else
+char *prs_alloc_mem(prs_struct *ps, size_t size, unsigned int count)
+#endif
{
char *ret = NULL;
if (size) {
- ret = talloc(ps->mem_ctx, size);
- if (ret)
- memset(ret, '\0', size);
+ /* We can't call the type-safe version here. */
+#if defined(PARANOID_MALLOC_CHECKER)
+ ret = talloc_zero_array_(ps->mem_ctx, size, count);
+#else
+ ret = talloc_zero_array(ps->mem_ctx, size, count);
+#endif
}
return ret;
}
@@ -199,7 +206,7 @@ BOOL prs_set_buffer_size(prs_struct *ps, uint32 newsize)
return prs_force_grow(ps, newsize - ps->buffer_size);
if (newsize < ps->buffer_size) {
- char *new_data_p = Realloc(ps->data_p, newsize);
+ char *new_data_p = SMB_REALLOC(ps->data_p, newsize);
/* if newsize is zero, Realloc acts like free() & returns NULL*/
if (new_data_p == NULL && newsize != 0) {
DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n",
@@ -253,7 +260,7 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
- if((new_data = malloc(new_size)) == NULL) {
+ if((new_data = SMB_MALLOC(new_size)) == NULL) {
DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
return False;
}
@@ -265,7 +272,7 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
*/
new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);
- if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+ if ((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
(unsigned int)new_size));
return False;
@@ -296,7 +303,7 @@ BOOL prs_force_grow(prs_struct *ps, uint32 extra_space)
return False;
}
- if((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+ if((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
(unsigned int)new_size));
return False;
@@ -886,7 +893,7 @@ BOOL prs_buffer5(BOOL charmode, const char *name, prs_struct *ps, int depth, BUF
return False;
if (UNMARSHALLING(ps)) {
- str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len * sizeof(uint16));
+ str->buffer = PRS_ALLOC_MEM(ps,uint16,str->buf_len);
if (str->buffer == NULL)
return False;
}
@@ -918,7 +925,7 @@ BOOL prs_buffer2(BOOL charmode, const char *name, prs_struct *ps, int depth, BUF
if (UNMARSHALLING(ps)) {
if ( str->buf_len ) {
- str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len);
+ str->buffer = PRS_ALLOC_MEM(ps, uint16, str->buf_len);
if ( str->buffer == NULL )
return False;
}
@@ -945,7 +952,7 @@ BOOL prs_string2(BOOL charmode, const char *name, prs_struct *ps, int depth, STR
return False;
if (UNMARSHALLING(ps)) {
- str->buffer = (unsigned char *)prs_alloc_mem(ps,str->str_max_len);
+ str->buffer = PRS_ALLOC_MEM(ps,unsigned char, str->str_max_len);
if (str->buffer == NULL)
return False;
}
@@ -989,7 +996,7 @@ BOOL prs_unistr2(BOOL charmode, const char *name, prs_struct *ps, int depth, UNI
return True;
if (UNMARSHALLING(ps)) {
- str->buffer = (uint16 *)prs_alloc_mem(ps,str->uni_max_len * sizeof(uint16));
+ str->buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_max_len);
if (str->buffer == NULL)
return False;
}
@@ -1016,7 +1023,7 @@ BOOL prs_unistr3(BOOL charmode, const char *name, UNISTR3 *str, prs_struct *ps,
return False;
if (UNMARSHALLING(ps)) {
- str->str.buffer = (uint16 *)prs_alloc_mem(ps,str->uni_str_len * sizeof(uint16));
+ str->str.buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_str_len);
if (str->str.buffer == NULL)
return False;
}
@@ -1109,7 +1116,7 @@ BOOL prs_unistr(const char *name, prs_struct *ps, int depth, UNISTR *str)
alloc_len += 1;
/* should we allocate anything at all? */
- str->buffer = (uint16 *)prs_alloc_mem(ps,alloc_len * sizeof(uint16));
+ str->buffer = PRS_ALLOC_MEM(ps,uint16,alloc_len);
if ((str->buffer == NULL) && (alloc_len > 0))
return False;
diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c
index ddae4bbdff..34f48b9ad7 100644
--- a/source3/rpc_parse/parse_samr.c
+++ b/source3/rpc_parse/parse_samr.c
@@ -1401,8 +1401,8 @@ BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
return False;
if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
+ r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
}
if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
@@ -1506,11 +1506,11 @@ NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 *sam, uint32 num_en
if (num_entries==0)
return NT_STATUS_OK;
- sam->sam=(SAM_ENTRY1 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY1));
+ sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
if (!sam->sam)
return NT_STATUS_NO_MEMORY;
- sam->str=(SAM_STR1 *)talloc(ctx, num_entries*sizeof(SAM_STR1));
+ sam->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
if (!sam->str)
return NT_STATUS_NO_MEMORY;
@@ -1584,16 +1584,12 @@ static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY1 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY1) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
return False;
}
- if ((sam->str = (SAM_STR1 *)
- prs_alloc_mem(ps, sizeof(SAM_STR1) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR1\n"));
return False;
}
@@ -1633,10 +1629,10 @@ NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 *sam, uint32 num_en
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY2 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY2))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR2 *)talloc(ctx, num_entries*sizeof(SAM_STR2))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
@@ -1697,16 +1693,12 @@ static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY2 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY2) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
return False;
}
- if ((sam->str = (SAM_STR2 *)
- prs_alloc_mem(ps, sizeof(SAM_STR2) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR2\n"));
return False;
}
@@ -1743,10 +1735,10 @@ NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 *sam, uint32 num_en
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY3 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY3))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR3 *)talloc(ctx, num_entries*sizeof(SAM_STR3))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
@@ -1788,16 +1780,12 @@ static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY3 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY3) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
return False;
}
- if ((sam->str = (SAM_STR3 *)
- prs_alloc_mem(ps, sizeof(SAM_STR3) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR3\n"));
return False;
}
@@ -1836,10 +1824,10 @@ NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 *sam, uint32 num_en
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY4 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY4))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR4 *)talloc(ctx, num_entries*sizeof(SAM_STR4))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
@@ -1880,16 +1868,12 @@ static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY4 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY4) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
return False;
}
- if ((sam->str = (SAM_STR4 *)
- prs_alloc_mem(ps, sizeof(SAM_STR4) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR4\n"));
return False;
}
@@ -1926,10 +1910,10 @@ NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 *sam, uint32 num_en
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY5 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY5))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR5 *)talloc(ctx, num_entries*sizeof(SAM_STR5))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
@@ -1970,16 +1954,12 @@ static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY5 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY5) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
return False;
}
- if ((sam->str = (SAM_STR5 *)
- prs_alloc_mem(ps, sizeof(SAM_STR5) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR5\n"));
return False;
}
@@ -2354,7 +2334,7 @@ static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
prs_struct *ps, int depth)
{
if (UNMARSHALLING(ps))
- *ctr = (GROUP_INFO_CTR *)prs_alloc_mem(ps,sizeof(GROUP_INFO_CTR));
+ *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
if (*ctr == NULL)
return False;
@@ -2929,7 +2909,7 @@ BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
return False;
if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
- r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
+ r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
if (r_u->rid == NULL)
return False;
}
@@ -2945,7 +2925,7 @@ BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
return False;
if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
- r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
+ r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
if (r_u->attr == NULL)
return False;
}
@@ -3046,7 +3026,7 @@ BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
if ((*num_gids) != 0) {
if (UNMARSHALLING(ps)) {
- (*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
+ (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
}
if ((*gid) == NULL) {
@@ -3201,8 +3181,8 @@ BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
return False;
if (UNMARSHALLING(ps)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+ r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
}
if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
@@ -3340,8 +3320,8 @@ BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
return False;
if (UNMARSHALLING(ps)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+ r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
}
if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
@@ -3474,8 +3454,8 @@ BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
return False;
if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+ r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
}
if (r_u->num_entries2 != 0 &&
@@ -3832,11 +3812,11 @@ BOOL samr_io_q_query_useraliases(const char *desc, SAMR_Q_QUERY_USERALIASES * q_
return False;
if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
- q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
+ q_u->ptr_sid = PRS_ALLOC_MEM(ps,uint32,q_u->num_sids2);
if (q_u->ptr_sid == NULL)
return False;
- q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
+ q_u->sid = PRS_ALLOC_MEM(ps, DOM_SID2, q_u->num_sids2);
if (q_u->sid == NULL)
return False;
}
@@ -3907,7 +3887,7 @@ BOOL samr_io_rids(const char *desc, uint32 *num_rids, uint32 **rid,
if ((*num_rids) != 0) {
if (UNMARSHALLING(ps)) {
/* reading */
- (*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
+ (*rid) = PRS_ALLOC_MEM(ps,uint32, *num_rids);
}
if ((*rid) == NULL)
return False;
@@ -4038,7 +4018,7 @@ 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 = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
+ q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
if (q_u->rid == NULL) {
q_u->num_rids1 = 0;
q_u->num_rids2 = 0;
@@ -4082,7 +4062,7 @@ BOOL samr_io_q_lookup_rids(const char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
return False;
if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
- q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
+ q_u->rid = PRS_ALLOC_MEM(ps, uint32, q_u->num_rids2);
if (q_u->rid == NULL)
return False;
}
@@ -4163,11 +4143,11 @@ BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
- r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
+ r_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, r_u->num_names2);
if (r_u->hdr_name == NULL)
return False;
- r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
+ r_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, r_u->num_names2);
if (r_u->uni_name == NULL)
return False;
}
@@ -4198,7 +4178,7 @@ BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
return False;
if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
- r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
+ r_u->type = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
if (r_u->type == NULL)
return False;
}
@@ -4624,7 +4604,7 @@ BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
return False;
- ptr_sid = talloc(ps->mem_ctx, sizeof(uint32) * r_u->num_sids1);
+ ptr_sid = TALLOC_ARRAY(ps->mem_ctx, uint32, r_u->num_sids1);
if (!ptr_sid) {
return False;
}
@@ -4636,7 +4616,7 @@ BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
}
if (UNMARSHALLING(ps)) {
- r_u->sid = talloc(ps->mem_ctx, r_u->num_sids1 * sizeof(DOM_SID2));
+ r_u->sid = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, r_u->num_sids1);
}
for (i = 0; i < r_u->num_sids1; i++) {
@@ -4674,10 +4654,10 @@ 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 = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
+ if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
return NT_STATUS_NO_MEMORY;
- if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
+ if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
return NT_STATUS_NO_MEMORY;
for (i = 0; i < num_names; i++) {
@@ -4722,10 +4702,8 @@ BOOL samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
return False;
if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
- q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
- q_u->num_names2);
- q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
- q_u->num_names2);
+ q_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_u->num_names2);
+ q_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_u->num_names2);
if (!q_u->hdr_name || !q_u->uni_name)
return False;
}
@@ -4765,9 +4743,9 @@ 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 = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
+ if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
return NT_STATUS_NO_MEMORY;
- if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
+ if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
return NT_STATUS_NO_MEMORY;
if (!r_u->rids || !r_u->types)
@@ -4834,7 +4812,7 @@ BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
}
if (UNMARSHALLING(ps))
- r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
+ r_u->rids = PRS_ALLOC_MEM(ps, uint32, r_u->num_rids2);
if (!r_u->rids) {
DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
@@ -4863,7 +4841,7 @@ BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
}
if (UNMARSHALLING(ps))
- r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
+ r_u->types = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
if (!r_u->types) {
DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
@@ -6282,7 +6260,7 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
switch (switch_value) {
case 0x10:
- ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
+ ctr->info.id10 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_10);
if (ctr->info.id10 == NULL)
return NT_STATUS_NO_MEMORY;
@@ -6298,7 +6276,7 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
expire.low = 0xffffffff;
expire.high = 0x7fffffff;
- ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
+ ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_11);
init_sam_user_info11(ctr->info.id11, &expire,
"BROOKFIELDS$", /* name */
0x03ef, /* user rid */
@@ -6309,7 +6287,7 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
}
#endif
case 0x12:
- ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
+ ctr->info.id12 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_12);
if (ctr->info.id12 == NULL)
return NT_STATUS_NO_MEMORY;
@@ -6318,7 +6296,7 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
case 21:
{
SAM_USER_INFO_21 *cusr;
- cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
+ cusr = TALLOC_ZERO_P(ctx,SAM_USER_INFO_21);
ctr->info.id21 = cusr;
if (ctr->info.id21 == NULL)
return NT_STATUS_NO_MEMORY;
@@ -6377,7 +6355,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
depth++;
if (UNMARSHALLING(ps)) {
- ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
+ ctr = PRS_ALLOC_MEM(ps,SAM_USERINFO_CTR,1);
if (ctr == NULL)
return False;
*ppctr = ctr;
@@ -6397,7 +6375,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
switch (ctr->switch_value) {
case 0x10:
if (UNMARSHALLING(ps))
- ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
+ ctr->info.id10 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_10,1);
if (ctr->info.id10 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
return False;
@@ -6406,7 +6384,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 0x11:
if (UNMARSHALLING(ps))
- ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
+ ctr->info.id11 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_11,1);
if (ctr->info.id11 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6416,7 +6394,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 0x12:
if (UNMARSHALLING(ps))
- ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
+ ctr->info.id12 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_12,1);
if (ctr->info.id12 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6426,7 +6404,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 20:
if (UNMARSHALLING(ps))
- ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
+ ctr->info.id20 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_20,1);
if (ctr->info.id20 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6436,7 +6414,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 21:
if (UNMARSHALLING(ps))
- ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
+ ctr->info.id21 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_21,1);
if (ctr->info.id21 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6446,7 +6424,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 23:
if (UNMARSHALLING(ps))
- ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
+ ctr->info.id23 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_23,1);
if (ctr->info.id23 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6456,7 +6434,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 24:
if (UNMARSHALLING(ps))
- ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
+ ctr->info.id24 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_24,1);
if (ctr->info.id24 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6466,7 +6444,7 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
break;
case 25:
if (UNMARSHALLING(ps))
- ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
+ ctr->info.id25 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_25,1);
if (ctr->info.id25 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -7356,7 +7334,7 @@ BOOL samr_io_q_set_domain_info(const char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
if(!prs_align(ps))
return False;
- if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
+ if ((q_u->ctr = PRS_ALLOC_MEM(ps, SAM_UNK_CTR, 1)) == NULL)
return False;
switch (q_u->switch_value) {
diff --git a/source3/rpc_parse/parse_sec.c b/source3/rpc_parse/parse_sec.c
index a78627650a..8656b8f5d8 100644
--- a/source3/rpc_parse/parse_sec.c
+++ b/source3/rpc_parse/parse_sec.c
@@ -129,7 +129,7 @@ BOOL sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth)
/*
* This is a read and we must allocate the stuct to read into.
*/
- if((psa = (SEC_ACL *)prs_alloc_mem(ps, sizeof(SEC_ACL))) == NULL)
+ if((psa = PRS_ALLOC_MEM(ps, SEC_ACL, 1)) == NULL)
return False;
*ppsa = psa;
}
@@ -154,7 +154,7 @@ BOOL sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth)
* between a non-present DACL (allow all access) and a DACL with no ACE's
* (allow no access).
*/
- if((psa->ace = (SEC_ACE *)prs_alloc_mem(ps,sizeof(psa->ace[0]) * (psa->num_aces+1))) == NULL)
+ if((psa->ace = PRS_ALLOC_MEM(ps, SEC_ACE, psa->num_aces+1)) == NULL)
return False;
}
@@ -191,7 +191,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
if (psd == NULL) {
if(UNMARSHALLING(ps)) {
- if((psd = (SEC_DESC *)prs_alloc_mem(ps,sizeof(SEC_DESC))) == NULL)
+ if((psd = PRS_ALLOC_MEM(ps,SEC_DESC,1)) == NULL)
return False;
*ppsd = psd;
} else {
@@ -244,7 +244,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
if (UNMARSHALLING(ps)) {
/* reading */
- if((psd->owner_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->owner_sid))) == NULL)
+ if((psd->owner_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
return False;
}
@@ -265,7 +265,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
if (UNMARSHALLING(ps)) {
/* reading */
- if((psd->grp_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->grp_sid))) == NULL)
+ if((psd->grp_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
return False;
}
@@ -324,7 +324,7 @@ BOOL sec_io_desc_buf(const char *desc, SEC_DESC_BUF **ppsdb, prs_struct *ps, int
psdb = *ppsdb;
if (UNMARSHALLING(ps) && psdb == NULL) {
- if((psdb = (SEC_DESC_BUF *)prs_alloc_mem(ps,sizeof(SEC_DESC_BUF))) == NULL)
+ if((psdb = PRS_ALLOC_MEM(ps,SEC_DESC_BUF,1)) == NULL)
return False;
*ppsdb = psdb;
}
diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c
index 6362dcf0f1..2e5244d653 100644
--- a/source3/rpc_parse/parse_spoolss.c
+++ b/source3/rpc_parse/parse_spoolss.c
@@ -269,7 +269,7 @@ static BOOL smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_
/* reading */
if (UNMARSHALLING(ps))
- if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
+ if((ctr->type=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION_TYPE,ctr->count)) == NULL)
return False;
/* the option type struct */
@@ -421,20 +421,20 @@ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *da
case NOTIFY_STRING:
- if (UNMARSHALLING(ps)) {
- data->notify_data.data.string =
- (uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
-
- if (!data->notify_data.data.string)
- return False;
- }
-
if (MARSHALLING(ps))
data->notify_data.data.length /= 2;
if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
return False;
+ if (UNMARSHALLING(ps)) {
+ data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
+ data->notify_data.data.length);
+
+ if (!data->notify_data.data.string)
+ return False;
+ }
+
if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string,
data->notify_data.data.length))
return False;
@@ -447,8 +447,8 @@ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *da
case NOTIFY_POINTER:
if (UNMARSHALLING(ps)) {
- data->notify_data.data.string =
- (uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
+ data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
+ data->notify_data.data.length);
if (!data->notify_data.data.string)
return False;
@@ -506,7 +506,7 @@ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *da
/* Tallocate memory for string */
- data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
+ data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, x * 2);
if (!data->notify_data.data.string)
return False;
@@ -679,7 +679,7 @@ BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE
depth++;
if (UNMARSHALLING(ps)) {
- devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
+ devmode->devicename.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
if (devmode->devicename.buffer == NULL)
return False;
}
@@ -745,7 +745,7 @@ BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE
return False;
if (UNMARSHALLING(ps)) {
- devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
+ devmode->formname.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
if (devmode->formname.buffer == NULL)
return False;
}
@@ -810,7 +810,7 @@ BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE
if (devmode->driverextra!=0) {
if (UNMARSHALLING(ps)) {
- devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
+ devmode->private=PRS_ALLOC_MEM(ps, uint8, devmode->driverextra);
if(devmode->private == NULL)
return False;
DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
@@ -856,7 +856,7 @@ static BOOL spoolss_io_devmode_cont(const char *desc, DEVMODE_CTR *dm_c, prs_str
/* so we have a DEVICEMODE to follow */
if (UNMARSHALLING(ps)) {
DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
- dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
+ dm_c->devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1);
if(dm_c->devmode == NULL)
return False;
}
@@ -1010,7 +1010,7 @@ BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2
SPOOL_PRINTER_INFO_LEVEL_2 *inf;
/* allocate the necessary memory */
- if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
+ if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2))) {
DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
return False;
}
@@ -1064,7 +1064,7 @@ BOOL make_spoolss_printer_info_3(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3
SPOOL_PRINTER_INFO_LEVEL_3 *inf;
/* allocate the necessary memory */
- if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_3*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_3)))) {
+ if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3))) {
DEBUG(0,("make_spoolss_printer_info_3: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_3 sruct!\n"));
return False;
}
@@ -1087,7 +1087,7 @@ BOOL make_spoolss_printer_info_7(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7
SPOOL_PRINTER_INFO_LEVEL_7 *inf;
/* allocate the necessary memory */
- if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_7*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_7)))) {
+ if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7))) {
DEBUG(0,("make_spoolss_printer_info_7: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_7 struct!\n"));
return False;
}
@@ -1444,7 +1444,7 @@ BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u,
return False;
if (UNMARSHALLING(ps) && r_u->size) {
- r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
+ r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
if(!r_u->data)
return False;
}
@@ -1885,7 +1885,7 @@ BOOL spoolss_io_q_writeprinter(const char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_
if (q_u->buffer_size!=0)
{
if (UNMARSHALLING(ps))
- q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
+ q_u->buffer=PRS_ALLOC_MEM(ps, uint8, q_u->buffer_size);
if(q_u->buffer == NULL)
return False;
if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
@@ -1952,7 +1952,7 @@ BOOL spoolss_io_q_rffpcnex(const char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *
if (q_u->option_ptr!=0) {
if (UNMARSHALLING(ps))
- if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+ if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
return False;
if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
@@ -2003,7 +2003,7 @@ BOOL spoolss_io_q_rfnpcnex(const char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *
if (q_u->option_ptr!=0) {
if (UNMARSHALLING(ps))
- if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+ if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
return False;
if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
@@ -2229,7 +2229,7 @@ static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth,
/* Yes this should be malloc not talloc. Don't change. */
- chaine.buffer = malloc((q-p+1)*sizeof(uint16));
+ chaine.buffer = SMB_MALLOC((q-p+1)*sizeof(uint16));
if (chaine.buffer == NULL)
return False;
@@ -2298,7 +2298,7 @@ static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth,
/* Yes this should be realloc - it's freed below. JRA */
- if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
+ if((tc2=(uint16 *)SMB_REALLOC(chaine2, realloc_size)) == NULL) {
SAFE_FREE(chaine2);
return False;
}
@@ -2314,7 +2314,7 @@ static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth,
if (chaine2)
{
chaine2[l_chaine2] = '\0';
- *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
+ *string=(uint16 *)TALLOC_MEMDUP(prs_get_mem_context(ps),chaine2,realloc_size);
SAFE_FREE(chaine2);
}
@@ -2442,7 +2442,7 @@ static BOOL smb_io_reldevmode(const char *desc, NEW_BUFFER *buffer, int depth, D
return False;
/* read the string */
- if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
+ if((*devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1)) == NULL)
return False;
if (!spoolss_io_devmode(desc, ps, depth, *devmode))
return False;
@@ -3114,7 +3114,7 @@ static BOOL spoolss_io_buffer(const char *desc, prs_struct *ps, int depth, NEW_B
depth++;
if (UNMARSHALLING(ps))
- buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
+ buffer = *pp_buffer = PRS_ALLOC_MEM(ps, NEW_BUFFER, 1);
if (buffer == NULL)
return False;
@@ -4172,7 +4172,7 @@ BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
#if 1 /* JERRY TEST */
- q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+ q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
if (!q_u->secdesc_ctr)
return False;
q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
@@ -4196,7 +4196,7 @@ BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
make_spoolss_printer_info_3 (mem_ctx, &q_u->info.info_3, info->printers_3);
- q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+ q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
if (!q_u->secdesc_ctr)
return False;
q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
@@ -5011,7 +5011,7 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
case 1:
{
if (UNMARSHALLING(ps)) {
- if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
+ if ((il->info_1=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_1,1)) == NULL)
return False;
}
if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
@@ -5024,7 +5024,7 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
*/
case 2:
if (UNMARSHALLING(ps)) {
- if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
+ if ((il->info_2=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_2,1)) == NULL)
return False;
}
if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
@@ -5034,7 +5034,7 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
case 3:
{
if (UNMARSHALLING(ps)) {
- if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
+ if ((il->info_3=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_3,1)) == NULL)
return False;
}
if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
@@ -5043,7 +5043,7 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
}
case 7:
if (UNMARSHALLING(ps))
- if ((il->info_7=(SPOOL_PRINTER_INFO_LEVEL_7 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_7))) == NULL)
+ if ((il->info_7=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_7,1)) == NULL)
return False;
if (!spool_io_printer_info_level_7("", il->info_7, ps, depth))
return False;
@@ -5148,7 +5148,7 @@ BOOL spool_io_printer_driver_info_level_3(const char *desc, SPOOL_PRINTER_DRIVER
/* reading */
if (UNMARSHALLING(ps)) {
- il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
+ il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_3,1);
if(il == NULL)
return False;
*q_u=il;
@@ -5226,7 +5226,7 @@ BOOL spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER
/* reading */
if (UNMARSHALLING(ps)) {
- il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
+ il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_6,1);
if(il == NULL)
return False;
*q_u=il;
@@ -5385,7 +5385,7 @@ static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE);
src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
- tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
+ tar = SMB_REALLOC_ARRAY(*ar, fstring, n+2);
if (!tar)
return False;
else
@@ -5499,7 +5499,7 @@ BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
BOOL null_char = False;
SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
- if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
+ if (!(inf=TALLOC_ZERO_P(mem_ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3)))
return False;
inf->cversion = info3->version;
@@ -5562,8 +5562,7 @@ BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16
{
buf5->buf_len = len;
- if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
- {
+ if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
return False;
}
@@ -5672,7 +5671,7 @@ BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
if (*asc==NULL)
{
- *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
+ *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
if(*asc == NULL)
return False;
ZERO_STRUCTP(*asc);
@@ -5719,7 +5718,7 @@ BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
if (*asc==NULL)
{
- *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
+ *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
if(*asc == NULL)
return False;
ZERO_STRUCTP(*asc);
@@ -5772,7 +5771,7 @@ BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
if (*asc==NULL) {
DEBUGADD(8,("allocating memory\n"));
- *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
+ *asc=SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2);
if(*asc == NULL)
return False;
ZERO_STRUCTP(*asc);
@@ -6168,7 +6167,7 @@ BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u
return False;
if (UNMARSHALLING(ps) && r_u->valuesize) {
- r_u->value = (uint16 *)prs_alloc_mem(ps, r_u->valuesize * 2);
+ r_u->value = PRS_ALLOC_MEM(ps, uint16, r_u->valuesize);
if (!r_u->value) {
DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
return False;
@@ -6191,7 +6190,7 @@ BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u
return False;
if (UNMARSHALLING(ps) && r_u->datasize) {
- r_u->data = (uint8 *)prs_alloc_mem(ps, r_u->datasize);
+ r_u->data = PRS_ALLOC_MEM(ps, uint8, r_u->datasize);
if (!r_u->data) {
DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
return False;
@@ -6326,7 +6325,7 @@ BOOL spoolss_io_q_setprinterdata(const char *desc, SPOOL_Q_SETPRINTERDATA *q_u,
case REG_MULTI_SZ:
if (q_u->max_len) {
if (UNMARSHALLING(ps))
- q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+ q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
if(q_u->data == NULL)
return False;
if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
@@ -6885,7 +6884,7 @@ static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
if (src->size != POINTER)
continue;
len = src->notify_data.data.length;
- s = malloc(sizeof(uint16)*len);
+ s = SMB_MALLOC_ARRAY(uint16, len);
if (s == NULL) {
DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
return False;
@@ -6914,7 +6913,7 @@ static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *sr
if (dst->count)
{
- dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
+ dst->data = SMB_MALLOC_ARRAY(SPOOL_NOTIFY_INFO_DATA, dst->count);
DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
dst->count));
@@ -7084,7 +7083,7 @@ BOOL spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r
return False;
if (UNMARSHALLING(ps) && r_u->size) {
- r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
+ r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
if(!r_u->data)
return False;
}
@@ -7142,7 +7141,7 @@ BOOL spoolss_io_q_setprinterdataex(const char *desc, SPOOL_Q_SETPRINTERDATAEX *q
case 0x7:
if (q_u->max_len) {
if (UNMARSHALLING(ps))
- q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+ q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
if(q_u->data == NULL)
return False;
if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
@@ -7350,8 +7349,7 @@ static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps,
/* first loop to write basic enum_value information */
if (UNMARSHALLING(ps)) {
- ctr->values = (PRINTER_ENUM_VALUES *)prs_alloc_mem(
- ps, ctr->size_of_array * sizeof(PRINTER_ENUM_VALUES));
+ ctr->values = PRS_ALLOC_MEM(ps, PRINTER_ENUM_VALUES, ctr->size_of_array);
if (!ctr->values)
return False;
}
@@ -7392,8 +7390,7 @@ static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps,
if ( ctr->values[i].data_len ) {
if ( UNMARSHALLING(ps) ) {
- ctr->values[i].data = (uint8 *)prs_alloc_mem(
- ps, ctr->values[i].data_len);
+ ctr->values[i].data = PRS_ALLOC_MEM(ps, uint8, ctr->values[i].data_len);
if (!ctr->values[i].data)
return False;
}
diff --git a/source3/rpc_parse/parse_srv.c b/source3/rpc_parse/parse_srv.c
index 8313c82c93..84c45b5901 100644
--- a/source3/rpc_parse/parse_srv.c
+++ b/source3/rpc_parse/parse_srv.c
@@ -783,7 +783,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info0 = (SRV_SHARE_INFO_0 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_0))))
+ if (!(info0 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_0, num_entries)))
return False;
ctr->share.info0 = info0;
}
@@ -809,7 +809,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1 = (SRV_SHARE_INFO_1 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_1))))
+ if (!(info1 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_1, num_entries)))
return False;
ctr->share.info1 = info1;
}
@@ -835,7 +835,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info2 = (SRV_SHARE_INFO_2 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_2))))
+ if (!(info2 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_2,num_entries)))
return False;
ctr->share.info2 = info2;
}
@@ -860,8 +860,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info501 = (SRV_SHARE_INFO_501 *) prs_alloc_mem(ps, num_entries *
- sizeof (SRV_SHARE_INFO_501))))
+ if (!(info501 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_501, num_entries)))
return False;
ctr->share.info501 = info501;
}
@@ -886,7 +885,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info502 = (SRV_SHARE_INFO_502 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_502))))
+ if (!(info502 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_502,num_entries)))
return False;
ctr->share.info502 = info502;
}
@@ -912,7 +911,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1004 = (SRV_SHARE_INFO_1004 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1004))))
+ if (!(info1004 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1004,num_entries)))
return False;
ctr->share.info1004 = info1004;
}
@@ -938,7 +937,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1005 = (SRV_SHARE_INFO_1005 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1005))))
+ if (!(info1005 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1005,num_entries)))
return False;
ctr->share.info1005 = info1005;
}
@@ -958,7 +957,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1006 = (SRV_SHARE_INFO_1006 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1006))))
+ if (!(info1006 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1006,num_entries)))
return False;
ctr->share.info1006 = info1006;
}
@@ -978,7 +977,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1007 = (SRV_SHARE_INFO_1007 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1007))))
+ if (!(info1007 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1007,num_entries)))
return False;
ctr->share.info1007 = info1007;
}
@@ -1004,7 +1003,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1501 = (SRV_SHARE_INFO_1501 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1501))))
+ if (!(info1501 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1501,num_entries)))
return False;
ctr->share.info1501 = info1501;
}
@@ -1848,7 +1847,7 @@ static BOOL srv_io_srv_sess_ctr(const char *desc, SRV_SESS_INFO_CTR **pp_ctr, pr
depth++;
if(UNMARSHALLING(ps)) {
- ctr = *pp_ctr = (SRV_SESS_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_SESS_INFO_CTR));
+ ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_SESS_INFO_CTR, 1);
if (ctr == NULL)
return False;
}
@@ -2221,7 +2220,7 @@ static BOOL srv_io_srv_conn_ctr(const char *desc, SRV_CONN_INFO_CTR **pp_ctr, pr
depth++;
if (UNMARSHALLING(ps)) {
- ctr = *pp_ctr = (SRV_CONN_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_CONN_INFO_CTR));
+ ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_CONN_INFO_CTR, 1);
if (ctr == NULL)
return False;
}
@@ -2487,7 +2486,7 @@ static BOOL srv_io_srv_file_ctr(const char *desc, SRV_FILE_INFO_CTR *ctr, prs_st
int i;
if (UNMARSHALLING(ps)) {
- if (!(info3 = (SRV_FILE_INFO_3 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_FILE_INFO_3))))
+ if (!(info3 = PRS_ALLOC_MEM(ps, SRV_FILE_INFO_3, num_entries)))
return False;
ctr->file.info3 = info3;
}
@@ -3022,8 +3021,7 @@ BOOL srv_io_q_net_srv_set_info(const char *desc, SRV_Q_NET_SRV_SET_INFO *q_n,
return False;
if (UNMARSHALLING(ps)) {
- q_n->ctr = (SRV_INFO_CTR *)
- prs_alloc_mem(ps, sizeof(SRV_INFO_CTR));
+ q_n->ctr = PRS_ALLOC_MEM(ps, SRV_INFO_CTR, 1);
if (!q_n->ctr)
return False;
@@ -3310,8 +3308,8 @@ BOOL srv_io_r_net_disk_enum(const char *desc, SRV_R_NET_DISK_ENUM *r_n, prs_stru
DISK_INFO *dinfo;
- if(!(dinfo = (DISK_INFO *)prs_alloc_mem(ps, sizeof(*dinfo) * entries_read3)))
- return False;
+ if(!(dinfo = PRS_ALLOC_MEM(ps, DISK_INFO, entries_read3)))
+ return False;
r_n->disk_enum_ctr.disk_info = dinfo;
}