diff options
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r-- | source3/rpc_parse/parse_lsa.c | 10 | ||||
-rw-r--r-- | source3/rpc_parse/parse_misc.c | 103 | ||||
-rw-r--r-- | source3/rpc_parse/parse_spoolss.c | 4 |
3 files changed, 71 insertions, 46 deletions
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c index a33c759473..d86df0ee11 100644 --- a/source3/rpc_parse/parse_lsa.c +++ b/source3/rpc_parse/parse_lsa.c @@ -708,7 +708,7 @@ static BOOL lsa_io_dom_query_2(char *desc, DOM_QUERY_2 *d_q, prs_struct *ps, int return False; if (UNMARSHALLING(ps)) { - d_q->auditsettings = (uint32 *)talloc(ps->mem_ctx, d_q->count2 * sizeof(uint32)); + d_q->auditsettings = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32)); } if (d_q->auditsettings == NULL) { @@ -829,13 +829,13 @@ void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen, if (num_entries == 0) return; - if ((sen->ptr_sid = (uint32 *)talloc(mem_ctx, num_entries * + if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries * sizeof(uint32))) == NULL) { DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n")); return; } - if ((sen->sid = (DOM_SID2 *)talloc(mem_ctx, num_entries * + if ((sen->sid = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries * sizeof(DOM_SID2))) == NULL) { DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n")); return; @@ -1070,13 +1070,13 @@ 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( + if ((q_l->uni_name = (UNISTR2 *)talloc_zero( mem_ctx, num_names * sizeof(UNISTR2))) == NULL) { DEBUG(3, ("init_q_lookup_names(): out of memory\n")); return; } - if ((q_l->hdr_name = (UNIHDR *)talloc( + if ((q_l->hdr_name = (UNIHDR *)talloc_zero( mem_ctx, num_names * sizeof(UNIHDR))) == NULL) { DEBUG(3, ("init_q_lookup_names(): out of memory\n")); return; diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c index 329683d23a..0a65c09493 100644 --- a/source3/rpc_parse/parse_misc.c +++ b/source3/rpc_parse/parse_misc.c @@ -26,18 +26,66 @@ extern int DEBUGLEVEL; -static TALLOC_CTX *parse_misc_talloc = NULL; +/**************************************************************************** + A temporary TALLOC context for things like unistrs, that is valid for + the life of a complete RPC call. +****************************************************************************/ -/******************************************************************* a +static TALLOC_CTX *current_rpc_talloc = NULL; + +TALLOC_CTX *get_current_rpc_talloc(void) +{ + return current_rpc_talloc; +} + +void set_current_rpc_talloc( TALLOC_CTX *ctx) +{ + current_rpc_talloc = ctx; +} + +static TALLOC_CTX *main_loop_talloc = NULL; + +/******************************************************************* free up temporary memory - called from the main loop ********************************************************************/ -void parse_talloc_free(void) +void main_loop_talloc_free(void) { - if (!parse_misc_talloc) + if (!main_loop_talloc) return; - talloc_destroy(parse_misc_talloc); - parse_misc_talloc = NULL; + talloc_destroy(main_loop_talloc); + main_loop_talloc = NULL; +} + +/******************************************************************* + Get a talloc context that is freed in the main loop... +********************************************************************/ + +TALLOC_CTX *main_loop_talloc_get(void) +{ + if (!main_loop_talloc) { + main_loop_talloc = talloc_init(); + if (!main_loop_talloc) + smb_panic("main_loop_talloc: malloc fail\n"); + } + + return main_loop_talloc; +} + +/******************************************************************* + Try and get a talloc context. Get the rpc one if possible, else + get the main loop one. The main loop one is more dangerous as it + goes away between packets, the rpc one will stay around for as long + as a current RPC lasts. +********************************************************************/ + +TALLOC_CTX *get_talloc_ctx(void) +{ + TALLOC_CTX *tc = get_current_rpc_talloc(); + + if (tc) + return tc; + return main_loop_talloc_get(); } /******************************************************************* @@ -483,19 +531,14 @@ void init_unistr(UNISTR *str, const char *buf) len = strlen(buf) + 1; - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - if (len < MAX_UNISTRLEN) len = MAX_UNISTRLEN; len *= sizeof(uint16); - str->buffer = (uint16 *)talloc(parse_misc_talloc, len); + str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len); if (str->buffer == NULL) smb_panic("init_unistr: malloc fail\n"); - memset(str->buffer, '\0', len); - /* store the string (null-terminated copy) */ dos_struni2((char *)str->buffer, buf, len); } @@ -527,15 +570,12 @@ BOOL smb_io_unistr(char *desc, UNISTR *uni, prs_struct *ps, int depth) static void create_buffer3(BUFFER3 *str, size_t len) { - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - if (len < MAX_BUFFERLEN) len = MAX_BUFFERLEN; - str->buffer = talloc(parse_misc_talloc, len); + str->buffer = talloc_zero(get_talloc_ctx(), len); if (str->buffer == NULL) - smb_panic("create_buffer3: malloc fail\n"); + smb_panic("create_buffer3: talloc fail\n"); } @@ -673,14 +713,11 @@ void init_buffer2(BUFFER2 *str, uint8 *buf, int len) str->buf_len = buf != NULL ? len : 0; if (buf != NULL) { - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - if (len < MAX_BUFFERLEN) len = MAX_BUFFERLEN; - str->buffer = talloc(parse_misc_talloc, len); + str->buffer = talloc_zero(get_talloc_ctx(), len); if (str->buffer == NULL) - smb_panic("init_buffer2: malloc fail\n"); + smb_panic("init_buffer2: talloc fail\n"); memcpy(str->buffer, buf, MIN(str->buf_len, len)); } } @@ -767,17 +804,14 @@ void copy_unistr2(UNISTR2 *str, UNISTR2 *from) if (str->buffer == NULL) { size_t len = from->uni_max_len * sizeof(uint16); - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - if (len < MAX_UNISTRLEN) len = MAX_UNISTRLEN; len *= sizeof(uint16); - str->buffer = (uint16 *)talloc(parse_misc_talloc, len); + str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len); if ((str->buffer == NULL) && (len > 0 )) { - smb_panic("copy_unistr2: malloc fail\n"); + smb_panic("copy_unistr2: talloc fail\n"); return; } } @@ -801,12 +835,9 @@ void init_string2(STRING2 *str, char *buf, int len) /* store the string */ if(len != 0) { - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - if (len < MAX_STRINGLEN) alloc_len = MAX_STRINGLEN; - str->buffer = talloc(parse_misc_talloc, alloc_len); + str->buffer = talloc_zero(get_talloc_ctx(), alloc_len); if (str->buffer == NULL) smb_panic("init_string2: malloc fail\n"); memcpy(str->buffer, buf, len); @@ -869,14 +900,11 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len) str->undoc = 0; str->uni_str_len = (uint32)len; - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - if (len < MAX_UNISTRLEN) len = MAX_UNISTRLEN; len *= sizeof(uint16); - str->buffer = (uint16 *)talloc(parse_misc_talloc, len); + str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len); if ((str->buffer == NULL) && (len > 0)) { smb_panic("init_unistr2: malloc fail\n"); @@ -917,11 +945,8 @@ void init_unistr2_from_unistr (UNISTR2 *to, UNISTR *from) to->undoc = 0; to->uni_str_len = i; - if (!parse_misc_talloc) - parse_misc_talloc = talloc_init(); - /* allocate the space and copy the string buffer */ - to->buffer = (uint16 *)talloc(parse_misc_talloc, sizeof(uint16)*(to->uni_str_len)); + to->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len)); if (to->buffer == NULL) smb_panic("init_unistr2_from_unistr: malloc fail\n"); memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16)); diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c index 0961cda195..bb8c818421 100644 --- a/source3/rpc_parse/parse_spoolss.c +++ b/source3/rpc_parse/parse_spoolss.c @@ -401,10 +401,10 @@ BOOL smb_io_notify_info_data_strings(char *desc,SPOOL_NOTIFY_INFO_DATA *data, /* Tallocate memory for string */ - DEBUG(0, ("** tallocating memory\n")); + DEBUG(10, ("** tallocating memory\n")); data->notify_data.data.string = (uint16 *) - talloc(ps->mem_ctx, x * 2); + talloc_zero(ps->mem_ctx, x * 2); if (!data->notify_data.data.string) return False; |