diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-07 04:39:16 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:08:30 -0500 |
commit | 11ce2cfd70df264c5c91b4daaa9a01c5abc673b0 (patch) | |
tree | f00bf95389509ca8655f3b1cf1dfec76289790b3 /source4 | |
parent | 066134f2414e8688fd980b619f9e597538c8766d (diff) | |
download | samba-11ce2cfd70df264c5c91b4daaa9a01c5abc673b0.tar.gz samba-11ce2cfd70df264c5c91b4daaa9a01c5abc673b0.tar.bz2 samba-11ce2cfd70df264c5c91b4daaa9a01c5abc673b0.zip |
r4591: - converted the other _p talloc functions to not need _p
- added #if TALLOC_DEPRECATED around the _p functions
- fixes the code that broke from the above
while doing this I fixed quite a number of places that were
incorrectly using the non type-safe talloc functions to use the type
safe ones. Some were even doing multiplies for array allocation, which
is potentially unsafe.
(This used to be commit 6e7754abd0c225527fb38363996a6e241b87b37e)
Diffstat (limited to 'source4')
39 files changed, 136 insertions, 105 deletions
diff --git a/source4/auth/auth_sam.c b/source4/auth/auth_sam.c index 236a68fe9d..a261fb223f 100644 --- a/source4/auth/auth_sam.c +++ b/source4/auth/auth_sam.c @@ -379,7 +379,7 @@ NTSTATUS sam_make_server_info(TALLOC_CTX *mem_ctx, void *sam_ctx, } if (group_ret > 0 && - !(groupSIDs = talloc_array_p(*server_info, struct dom_sid *, group_ret))) { + !(groupSIDs = talloc_array(*server_info, struct dom_sid *, group_ret))) { talloc_free(*server_info); return NT_STATUS_NO_MEMORY; } diff --git a/source4/dsdb/samdb/samdb.c b/source4/dsdb/samdb/samdb.c index d84d07fca6..9dbf1f9882 100644 --- a/source4/dsdb/samdb/samdb.c +++ b/source4/dsdb/samdb/samdb.c @@ -858,7 +858,7 @@ int samdb_msg_add_hashes(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg struct ldb_wrap *sam_ctx = ctx; struct ldb_val val; int i; - val.data = talloc_array(mem_ctx, 16, count, __location__); + val.data = talloc_array_size(mem_ctx, 16, count); val.length = count*16; if (!val.data) { return -1; diff --git a/source4/include/includes.h b/source4/include/includes.h index 2666d59f89..4d49a3b1ff 100644 --- a/source4/include/includes.h +++ b/source4/include/includes.h @@ -154,6 +154,7 @@ extern int errno; /* Lists, trees, caching, database... */ #include "version.h" #include "xfile.h" +#define TALLOC_DEPRECATED 1 #include "lib/talloc/talloc.h" #include "nt_status.h" #include "structs.h" diff --git a/source4/lib/charcnv.c b/source4/lib/charcnv.c index 7e9750e948..d5727feb2c 100644 --- a/source4/lib/charcnv.c +++ b/source4/lib/charcnv.c @@ -229,7 +229,7 @@ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, outbuf = NULL; convert: destlen = 2 + (destlen*3); - ob = (char *)talloc_realloc(ctx, outbuf, destlen); + ob = talloc_realloc(ctx, outbuf, char, destlen); if (!ob) { DEBUG(0, ("convert_string_talloc: realloc failed!\n")); talloc_free(outbuf); diff --git a/source4/lib/registry/common/reg_util.c b/source4/lib/registry/common/reg_util.c index 67c62fe5c8..ef46dd6174 100644 --- a/source4/lib/registry/common/reg_util.c +++ b/source4/lib/registry/common/reg_util.c @@ -63,7 +63,7 @@ char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct registry_value *v) return ret; case REG_BINARY: - ret = talloc_array(mem_ctx, 3, v->data_len+1, "REG_BINARY"); + ret = talloc_array_size(mem_ctx, 3, v->data_len+1); asciip = ret; for (i=0; i<v->data_len; i++) { int str_rem = v->data_len * 3 - (asciip - ret); diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index bcadf40cfb..6d11cb00e9 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -932,7 +932,7 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) } len = vsnprintf(NULL, 0, fmt, ap2); - s = talloc_realloc(NULL, s, s_len + len+1); + s = talloc_realloc(NULL, s, char, s_len + len+1); if (!s) return NULL; VA_COPY(ap2, ap); @@ -961,7 +961,7 @@ char *talloc_asprintf_append(char *s, const char *fmt, ...) /* alloc an array, checking for integer overflow in the array size */ -void *talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name) +void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name) { if (count >= MAX_TALLOC_SIZE/el_size) { return NULL; @@ -972,7 +972,7 @@ void *talloc_array(const void *ctx, size_t el_size, unsigned count, const char * /* alloc an zero array, checking for integer overflow in the array size */ -void *talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name) +void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name) { if (count >= MAX_TALLOC_SIZE/el_size) { return NULL; @@ -984,16 +984,12 @@ void *talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const c /* realloc an array, checking for integer overflow in the array size */ -void *talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name) +void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name) { if (count >= MAX_TALLOC_SIZE/el_size) { return NULL; } - ptr = talloc_realloc(ctx, ptr, el_size * count); - if (ptr) { - talloc_set_name_const(ptr, name); - } - return ptr; + return _talloc_realloc(ctx, ptr, el_size * count, name); } /* diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h index 747b1c6ba6..8169782441 100644 --- a/source4/lib/talloc/talloc.h +++ b/source4/lib/talloc/talloc.h @@ -32,17 +32,26 @@ typedef void TALLOC_CTX; #define __LINESTR__ _STRING_LINE2_(__LINE__) #define __location__ __FILE__ ":" __LINESTR__ +#ifndef TALLOC_DEPRECATED +#define TALLOC_DEPRECATED 0 +#endif + /* useful macros for creating type checked pointers */ #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type) -#define talloc_p(ctx, type) talloc(ctx, type) #define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__) -#define talloc_zero(ctx, size) _talloc_zero(ctx, size, __location__) -#define talloc_realloc(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__) + #define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__) -#define talloc_zero_p(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type) -#define talloc_zero_array_p(ctx, type, count) (type *)talloc_zero_array(ctx, sizeof(type), count, __location__) -#define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count, __location__) -#define talloc_realloc_p(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count, __location__) + +#define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type) +#define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__) + +#define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, __location__) +#define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, __location__) +#define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__) + +#define talloc_realloc(ctx, p, type, count) (type *)_talloc_realloc_array(ctx, p, sizeof(type), count, __location__) +#define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__) + #define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__) #define talloc_destroy(ctx) talloc_free(ctx) @@ -54,6 +63,14 @@ typedef void TALLOC_CTX; #define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__) #define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__) + +#if TALLOC_DEPRECATED +#define talloc_zero_p(ctx, type) talloc_zero(ctx, type) +#define talloc_p(ctx, type) talloc(ctx, type) +#define talloc_array_p(ctx, type, count) talloc_array(ctx, type, count) +#define talloc_realloc_p(ctx, p, type, count) talloc_realloc(ctx, p, type, count) +#endif + #ifndef PRINTF_ATTRIBUTE #define PRINTF_ATTRIBUTE(a1, a2) #endif @@ -89,9 +106,9 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIB char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); -void *talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name); -void *talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name); -void *talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name); +void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name); +void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name); +void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name); void *talloc_realloc_fn(const void *context, void *ptr, size_t size); void *talloc_autofree_context(void); diff --git a/source4/lib/talloc/talloc_guide.txt b/source4/lib/talloc/talloc_guide.txt index af6bdf0275..30b7f64d67 100644 --- a/source4/lib/talloc/talloc_guide.txt +++ b/source4/lib/talloc/talloc_guide.txt @@ -5,7 +5,7 @@ Andrew Tridgell September 2004 The most current version of this document is available at - http://samba.org/ftp/unpacked/samba4/talloc_guide.txt + http://samba.org/ftp/unpacked/samba4/source/lib/talloc/talloc_guide.txt If you are used to talloc from Samba3 then please read this carefully, as talloc has changed a lot. @@ -19,7 +19,7 @@ between a "talloc context" and a "talloc pointer". Any pointer returned from talloc() is itself a valid talloc context. This means you can do this: - struct foo *X = talloc_p(mem_ctx, struct foo); + struct foo *X = talloc(mem_ctx, struct foo); X->name = talloc_strdup(X, "foo"); and the pointer X->name would be a "child" of the talloc context "X" @@ -34,7 +34,7 @@ talloc_free(). If you find this confusing, then I suggest you run the LOCAL-TALLOC smbtorture test to watch talloc in action. You may also like to add -your own tests to source/torture/local/talloc.c to clarify how some +your own tests to source/lib/talloc/testsuite.c to clarify how some particular situation is handled. @@ -270,13 +270,13 @@ particularly useful for creating a new temporary working context. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -void *talloc_realloc(const void *context, void *ptr, size_t size); +(type *)talloc_realloc(const void *context, void *ptr, type, count); -The talloc_realloc() function changes the size of a talloc +The talloc_realloc() macro changes the size of a talloc pointer. It has the following equivalences: - talloc_realloc(context, NULL, size) ==> talloc_size(context, size); - talloc_realloc(context, ptr, 0) ==> talloc_free(ptr); + talloc_realloc(context, NULL, type, 1) ==> talloc(context, type); + talloc_realloc(context, ptr, type, 0) ==> talloc_free(ptr); The "context" argument is only used if "ptr" is not NULL, otherwise it is ignored. @@ -287,6 +287,13 @@ more than one parent (see talloc_reference()). =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +void *talloc_realloc_size(const void *context, void *ptr, size_t size); + +the talloc_realloc_size() function is useful when the type is not +known so the typesafe talloc_realloc() cannot be used. + + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- void *talloc_steal(const void *new_ctx, const void *ptr); The talloc_steal() function changes the parent context of a talloc @@ -403,12 +410,18 @@ full talloc report on 'root' (total 18 bytes in 8 blocks) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -void *talloc_zero(const void *ctx, size_t size); +(type *)talloc_zero(const void *ctx, type); -The talloc_zero() function is equivalent to: +The talloc_zero() macro is equivalent to: - ptr = talloc_size(ctx, size); - if (ptr) memset(ptr, 0, size); + ptr = talloc(ctx, type); + if (ptr) memset(ptr, 0, sizeof(type)); + + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +void *talloc_zero_size(const void *ctx, size_t size) + +The talloc_zero_size() function is useful when you don't have a known type =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- @@ -469,25 +482,19 @@ string to the given string. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -void *talloc_array_p(const void *ctx, type, uint_t count); +(type *)talloc_array(const void *ctx, type, uint_t count); -The talloc_array_p() macro is equivalent to: +The talloc_array() macro is equivalent to: (type *)talloc_size(ctx, sizeof(type) * count); except that it provides integer overflow protection for the multiply, returning NULL if the multiply overflows. - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -void *talloc_realloc_p(const void *ctx, void *ptr, type, uint_t count); - -The talloc_realloc_p() macro is equivalent to: +void *talloc_array_size(const void *ctx, size_t size, uint_t count); - (type *)talloc_realloc(ctx, ptr, sizeof(type) * count); - -except that it provides integer overflow protection for the multiply, -returning NULL if the multiply overflows. +The talloc_array_size() function is useful when the type is not known =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index d46964d9b6..e7934a10f3 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -398,7 +398,7 @@ static BOOL test_misc(void) talloc_report(root, stdout); - p2 = talloc_zero(p1, 20); + p2 = talloc_zero_size(p1, 20); if (p2[19] != 0) { printf("Failed to give zero memory\n"); return False; @@ -520,41 +520,41 @@ static BOOL test_realloc(void) p1 = talloc_size(root, 10); CHECK_SIZE(p1, 10); - p1 = talloc_realloc(NULL, p1, 20); + p1 = talloc_realloc_size(NULL, p1, 20); CHECK_SIZE(p1, 20); talloc_new(p1); - p2 = talloc_realloc(p1, NULL, 30); + p2 = talloc_realloc_size(p1, NULL, 30); talloc_new(p1); - p2 = talloc_realloc(p1, p2, 40); + p2 = talloc_realloc_size(p1, p2, 40); CHECK_SIZE(p2, 40); CHECK_SIZE(root, 60); CHECK_BLOCKS(p1, 4); - p1 = talloc_realloc(NULL, p1, 20); + p1 = talloc_realloc_size(NULL, p1, 20); CHECK_SIZE(p1, 60); talloc_increase_ref_count(p2); - if (talloc_realloc(NULL, p2, 5) != NULL) { + if (talloc_realloc_size(NULL, p2, 5) != NULL) { printf("failed: talloc_realloc() on a referenced pointer should fail\n"); return False; } CHECK_BLOCKS(p1, 4); - talloc_realloc(NULL, p2, 0); - talloc_realloc(NULL, p2, 0); + talloc_realloc_size(NULL, p2, 0); + talloc_realloc_size(NULL, p2, 0); CHECK_BLOCKS(p1, 3); - if (talloc_realloc(NULL, p1, 0x7fffffff) != NULL) { + if (talloc_realloc_size(NULL, p1, 0x7fffffff) != NULL) { printf("failed: oversize talloc should fail\n"); return False; } - talloc_realloc(NULL, p1, 0); + talloc_realloc_size(NULL, p1, 0); CHECK_BLOCKS(root, 1); CHECK_SIZE(root, 0); diff --git a/source4/libcli/auth/spnego_parse.c b/source4/libcli/auth/spnego_parse.c index 32e98a4235..78a94a6a44 100644 --- a/source4/libcli/auth/spnego_parse.c +++ b/source4/libcli/auth/spnego_parse.c @@ -52,9 +52,9 @@ static BOOL read_negTokenInit(struct asn1_data *asn1, struct spnego_negTokenInit token->mechTypes = talloc_p(NULL, const char *); for (i = 0; !asn1->has_error && 0 < asn1_tag_remaining(asn1); i++) { - token->mechTypes = - talloc_realloc(NULL, token->mechTypes, (i + 2) * - sizeof(*token->mechTypes)); + token->mechTypes = talloc_realloc(NULL, + token->mechTypes, + const char *, i+2); asn1_read_OID(asn1, token->mechTypes + i); if (token->mechTypes[i]) { talloc_steal(token->mechTypes, diff --git a/source4/libcli/clilist.c b/source4/libcli/clilist.c index ec103dbfa4..77fd760837 100644 --- a/source4/libcli/clilist.c +++ b/source4/libcli/clilist.c @@ -81,13 +81,13 @@ static BOOL smbcli_list_new_callback(void *private, union smb_search_data *file) /* add file info to the dirlist pool */ tdl = talloc_realloc(state, state->dirlist, - state->dirlist_len + sizeof(struct clilist_file_info)); - + struct clilist_file_info, + state->dirlist_len + 1); if (!tdl) { return False; } state->dirlist = tdl; - state->dirlist_len += sizeof(struct clilist_file_info); + state->dirlist_len++; interpret_long_filename(state->info_level, file, &state->dirlist[state->total_received]); @@ -227,13 +227,14 @@ static BOOL smbcli_list_old_callback(void *private, union smb_search_data *file) /* add file info to the dirlist pool */ tdl = talloc_realloc(state, state->dirlist, - state->dirlist_len + sizeof(struct clilist_file_info)); + struct clilist_file_info, + state->dirlist_len + 1); if (!tdl) { return False; } state->dirlist = tdl; - state->dirlist_len += sizeof(struct clilist_file_info); + state->dirlist_len++; interpret_short_filename(state->info_level, file, &state->dirlist[state->total_received]); diff --git a/source4/libcli/ldap/ldap_ldif.c b/source4/libcli/ldap/ldap_ldif.c index c276b7e917..809c75cf96 100644 --- a/source4/libcli/ldap/ldap_ldif.c +++ b/source4/libcli/ldap/ldap_ldif.c @@ -52,7 +52,7 @@ static char *next_chunk(TALLOC_CTX *mem_ctx, if (chunk_size+1 >= alloc_size) { char *c2; alloc_size += 1024; - c2 = talloc_realloc(mem_ctx, chunk, alloc_size); + c2 = talloc_realloc(mem_ctx, chunk, char, alloc_size); if (!c2) { errno = ENOMEM; return NULL; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 918fb788cb..e48545419f 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -73,7 +73,7 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, } /* allocate array */ - parms->out.changes = talloc_array_p(mem_ctx, struct notify_changes, parms->out.num_changes); + parms->out.changes = talloc_array(mem_ctx, struct notify_changes, parms->out.num_changes); if (!parms->out.changes) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index b74f066ef4..8093b298bb 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -203,7 +203,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si /* we need to realloc */ req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; - buf2 = talloc_realloc(req, req->out.buffer, req->out.allocated); + buf2 = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated); if (buf2 == NULL) { smb_panic("out of memory in req_grow_allocation"); } @@ -950,7 +950,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; - blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len); + blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length + max_len); if (!blob->data) { return 0; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 0ccecdc2d4..118ac5e3fd 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -111,7 +111,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, if (parms->out.setup_count > 0) { int i; - parms->out.setup = talloc_array(mem_ctx, 2, parms->out.setup_count, "setup"); + parms->out.setup = talloc_array(mem_ctx, uint16_t, parms->out.setup_count); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); @@ -439,7 +439,7 @@ NTSTATUS smb_raw_nttrans_recv(struct smbcli_request *req, if (parms->out.setup_count > 0) { int i; - parms->out.setup = talloc_array(mem_ctx, 2, parms->out.setup_count, "setup"); + parms->out.setup = talloc_array(mem_ctx, uint16_t, parms->out.setup_count); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); diff --git a/source4/libcli/util/asn1.c b/source4/libcli/util/asn1.c index 52ba0225c9..de14eb0e57 100644 --- a/source4/libcli/util/asn1.c +++ b/source4/libcli/util/asn1.c @@ -33,7 +33,7 @@ BOOL asn1_write(struct asn1_data *data, const void *p, int len) if (data->has_error) return False; if (data->length < data->ofs+len) { uint8_t *newp; - newp = talloc_realloc(NULL, data->data, data->ofs+len); + newp = talloc_realloc(NULL, data->data, uint8_t, data->ofs+len); if (!newp) { asn1_free(data); data->has_error = True; diff --git a/source4/librpc/ndr/libndr.h b/source4/librpc/ndr/libndr.h index aebd9892ba..288e753cca 100644 --- a/source4/librpc/ndr/libndr.h +++ b/source4/librpc/ndr/libndr.h @@ -239,7 +239,7 @@ enum ndr_err_code { #define NDR_ALLOC_N_SIZE(ndr, s, n, elsize) do { \ - (s) = talloc_array(ndr, elsize, n, __location__); \ + (s) = talloc_array_size(ndr, elsize, n); \ if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u * %u failed\n", n, elsize); \ } while (0) diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c index 9ec22cdb79..7cc832c68e 100644 --- a/source4/librpc/ndr/ndr.c +++ b/source4/librpc/ndr/ndr.c @@ -173,7 +173,7 @@ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t size) if (size > ndr->alloc_size) { ndr->alloc_size = size; } - ndr->data = talloc_realloc(ndr, ndr->data, ndr->alloc_size); + ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size); if (!ndr->data) { return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u", ndr->alloc_size); diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c index 9a8de8c0ad..ee7250a4f9 100644 --- a/source4/librpc/rpc/dcerpc.c +++ b/source4/librpc/rpc/dcerpc.c @@ -811,6 +811,7 @@ static void dcerpc_request_recv_data(struct dcerpc_pipe *p, if (length > 0) { req->payload.data = talloc_realloc(req, req->payload.data, + uint8_t, req->payload.length + length); if (!req->payload.data) { req->status = NT_STATUS_NO_MEMORY; diff --git a/source4/librpc/rpc/dcerpc_smb.c b/source4/librpc/rpc/dcerpc_smb.c index d04b067eeb..ab8a60b060 100644 --- a/source4/librpc/rpc/dcerpc_smb.c +++ b/source4/librpc/rpc/dcerpc_smb.c @@ -94,7 +94,7 @@ static void smb_read_callback(struct smbcli_request *req) } /* initiate another read request, as we only got part of a fragment */ - state->data.data = talloc_realloc(state, state->data.data, frag_length); + state->data.data = talloc_realloc(state, state->data.data, uint8_t, frag_length); io->readx.in.mincnt = MIN(state->p->srv_max_xmit_frag, frag_length - state->received); diff --git a/source4/librpc/rpc/dcerpc_sock.c b/source4/librpc/rpc/dcerpc_sock.c index 8de43d8454..762a22ad3e 100644 --- a/source4/librpc/rpc/dcerpc_sock.c +++ b/source4/librpc/rpc/dcerpc_sock.c @@ -151,7 +151,7 @@ static void sock_process_recv(struct dcerpc_pipe *p) frag_length = dcerpc_get_frag_length(&sock->recv.data); sock->recv.data.data = talloc_realloc(sock, sock->recv.data.data, - frag_length); + uint8_t, frag_length); if (sock->recv.data.data == NULL) { sock_dead(p, NT_STATUS_NO_MEMORY); return; diff --git a/source4/ntvfs/posix/pvfs_dirlist.c b/source4/ntvfs/posix/pvfs_dirlist.c index 5c67b2d189..c2e8f826a2 100644 --- a/source4/ntvfs/posix/pvfs_dirlist.c +++ b/source4/ntvfs/posix/pvfs_dirlist.c @@ -137,9 +137,9 @@ NTSTATUS pvfs_list_start(struct pvfs_state *pvfs, struct pvfs_filename *name, dir->no_wildcard = False; dir->end_of_search = False; dir->offset = 0; - dir->name_cache = talloc_zero_array_p(dir, - struct name_cache_entry, - NAME_CACHE_SIZE); + dir->name_cache = talloc_zero_array(dir, + struct name_cache_entry, + NAME_CACHE_SIZE); if (dir->name_cache == NULL) { talloc_free(dir); return NT_STATUS_NO_MEMORY; diff --git a/source4/ntvfs/posix/pvfs_streams.c b/source4/ntvfs/posix/pvfs_streams.c index 12f783e172..e92732b810 100644 --- a/source4/ntvfs/posix/pvfs_streams.c +++ b/source4/ntvfs/posix/pvfs_streams.c @@ -283,7 +283,7 @@ ssize_t pvfs_stream_write(struct pvfs_state *pvfs, blob = data_blob(NULL, 0); } if (count+offset > blob.length) { - blob.data = talloc_realloc(blob.data, blob.data, count+offset); + blob.data = talloc_realloc(blob.data, blob.data, uint8_t, count+offset); if (blob.data == NULL) { errno = ENOMEM; return -1; @@ -339,7 +339,7 @@ NTSTATUS pvfs_stream_truncate(struct pvfs_state *pvfs, if (length <= blob.length) { blob.length = length; } else if (length > blob.length) { - blob.data = talloc_realloc(blob.data, blob.data, length); + blob.data = talloc_realloc(blob.data, blob.data, uint8_t, length); if (blob.data == NULL) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/ntvfs/posix/xattr_system.c b/source4/ntvfs/posix/xattr_system.c index c86ee0bd87..f19177f44c 100644 --- a/source4/ntvfs/posix/xattr_system.c +++ b/source4/ntvfs/posix/xattr_system.c @@ -51,7 +51,8 @@ again: } if (ret == -1 && errno == ERANGE) { estimated_size *= 2; - blob->data = talloc_realloc(mem_ctx, blob->data, estimated_size); + blob->data = talloc_realloc(mem_ctx, blob->data, + uint8_t, estimated_size); if (blob->data == NULL) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c index c53036b45b..f0791e5928 100644 --- a/source4/rpc_server/dcerpc_server.c +++ b/source4/rpc_server/dcerpc_server.c @@ -857,7 +857,9 @@ NTSTATUS dcesrv_input_process(struct dcesrv_connection *dce_conn) } call->pkt.u.request.stub_and_verifier.data = - talloc_realloc(call, call->pkt.u.request.stub_and_verifier.data, alloc_size); + talloc_realloc(call, + call->pkt.u.request.stub_and_verifier.data, + uint8_t, alloc_size); if (!call->pkt.u.request.stub_and_verifier.data) { return dcesrv_fault(call2, DCERPC_FAULT_OTHER); } @@ -920,6 +922,7 @@ NTSTATUS dcesrv_input(struct dcesrv_connection *dce_conn, const DATA_BLOB *data) dce_conn->partial_input.data = talloc_realloc(dce_conn, dce_conn->partial_input.data, + uint8_t, dce_conn->partial_input.length + data->length); if (!dce_conn->partial_input.data) { return NT_STATUS_NO_MEMORY; diff --git a/source4/smb_server/nttrans.c b/source4/smb_server/nttrans.c index 0ab9c9ce2e..5875554258 100644 --- a/source4/smb_server/nttrans.c +++ b/source4/smb_server/nttrans.c @@ -42,7 +42,7 @@ static void nttrans_setup_reply(struct smbsrv_request *req, { trans->out.setup_count = setup_count; if (setup_count != 0) { - trans->out.setup = talloc_zero_array_p(req, uint16_t, setup_count); + trans->out.setup = talloc_zero_array(req, uint16_t, setup_count); } trans->out.params = data_blob_talloc(req, NULL, param_size); trans->out.data = data_blob_talloc(req, NULL, data_size); diff --git a/source4/smb_server/reply.c b/source4/smb_server/reply.c index 0b49512663..2dfa3726e2 100644 --- a/source4/smb_server/reply.c +++ b/source4/smb_server/reply.c @@ -2377,7 +2377,7 @@ void reply_sendtxt(struct smbsrv_request *req) void reply_special(struct smbsrv_request *req) { uint8_t msg_type; - uint8_t *buf = talloc_zero_array_p(req, uint8_t, 4); + uint8_t *buf = talloc_zero_array(req, uint8_t, 4); msg_type = CVAL(req->in.buffer,0); diff --git a/source4/smb_server/request.c b/source4/smb_server/request.c index bd33e8cfc7..2ac832b439 100644 --- a/source4/smb_server/request.c +++ b/source4/smb_server/request.c @@ -83,7 +83,8 @@ static void req_setup_chain_reply(struct smbsrv_request *req, uint_t wct, uint_t /* over allocate by a small amount */ req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; - req->out.buffer = talloc_realloc(req, req->out.buffer, req->out.allocated); + req->out.buffer = talloc_realloc(req, req->out.buffer, + uint8_t, req->out.allocated); if (!req->out.buffer) { smbsrv_terminate_connection(req->smb_conn, "allocation failed"); return; @@ -236,7 +237,7 @@ static void req_grow_allocation(struct smbsrv_request *req, uint_t new_size) /* we need to realloc */ req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; - buf2 = talloc_realloc(req, req->out.buffer, req->out.allocated); + buf2 = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated); if (buf2 == NULL) { smb_panic("out of memory in req_grow_allocation"); } diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index 2ebb927f1e..0e845b9697 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -108,7 +108,8 @@ static NTSTATUS receive_smb_request(struct smbsrv_connection *smb_conn, struct t /* when we have a full NBT header, then allocate the packet */ if (req->in.size == NBT_HDR_SIZE) { len = smb_len(req->in.buffer) + NBT_HDR_SIZE; - req->in.buffer = talloc_realloc(req, req->in.buffer, len); + req->in.buffer = talloc_realloc(req, req->in.buffer, + uint8_t, len); if (req->in.buffer == NULL) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/smb_server/trans2.c b/source4/smb_server/trans2.c index 8aa60daa6d..2b9573383f 100644 --- a/source4/smb_server/trans2.c +++ b/source4/smb_server/trans2.c @@ -42,7 +42,8 @@ static BOOL trans2_grow_data_allocation(struct smbsrv_request *req, if (new_size <= trans->out.data.length) { return True; } - trans->out.data.data = talloc_realloc(req, trans->out.data.data, new_size); + trans->out.data.data = talloc_realloc(req, trans->out.data.data, + uint8_t, new_size); return (trans->out.data.data != NULL); } @@ -83,7 +84,7 @@ static void trans2_setup_reply(struct smbsrv_request *req, { trans->out.setup_count = setup_count; if (setup_count != 0) { - trans->out.setup = talloc_zero_array_p(req, uint16_t, setup_count); + trans->out.setup = talloc_zero_array(req, uint16_t, setup_count); } trans->out.params = data_blob_talloc(req, NULL, param_size); trans->out.data = data_blob_talloc(req, NULL, data_size); diff --git a/source4/torture/gentest.c b/source4/torture/gentest.c index 5d8c7bf8fd..81e2a59f34 100644 --- a/source4/torture/gentest.c +++ b/source4/torture/gentest.c @@ -1358,7 +1358,7 @@ static BOOL handler_writex(int instance) parm[0].writex.in.wmode = gen_bits_mask(0xFFFF); parm[0].writex.in.remaining = gen_io_count(); parm[0].writex.in.count = gen_io_count(); - parm[0].writex.in.data = talloc_zero(current_op.mem_ctx, parm[0].writex.in.count); + parm[0].writex.in.data = talloc_zero_size(current_op.mem_ctx, parm[0].writex.in.count); GEN_COPY_PARM; GEN_SET_FNUM(writex.in.fnum); diff --git a/source4/torture/local/idtree.c b/source4/torture/local/idtree.c index 3f30d7123f..94463cefa6 100644 --- a/source4/torture/local/idtree.c +++ b/source4/torture/local/idtree.c @@ -35,8 +35,8 @@ BOOL torture_local_idtree(void) idr = idr_init(ctx); - ids = talloc_zero_array_p(ctx, int, n); - present = talloc_zero_array_p(ctx, int, n); + ids = talloc_zero_array(ctx, int, n); + present = talloc_zero_array(ctx, int, n); for (i=0;i<n;i++) { ids[i] = -1; diff --git a/source4/torture/rap/rap.c b/source4/torture/rap/rap.c index b47cfa2997..0080a80951 100644 --- a/source4/torture/rap/rap.c +++ b/source4/torture/rap/rap.c @@ -82,6 +82,7 @@ static void rap_cli_push_paramdesc(struct rap_call *call, char desc) call->paramdesc = talloc_realloc(call->mem_ctx, call->paramdesc, + uint8_t, len+2); call->paramdesc[len] = desc; call->paramdesc[len+1] = '\0'; @@ -151,7 +152,7 @@ static NTSTATUS rap_pull_string(TALLOC_CTX *mem_ctx, struct ndr_pull *ndr, if ( string_offset + len + 1 > ndr->data_size ) return NT_STATUS_INVALID_PARAMETER; - *dest = talloc_zero(mem_ctx, len+1); + *dest = talloc_zero_size(mem_ctx, len+1); pull_ascii(*dest, p, len+1, len, 0); return NT_STATUS_OK; diff --git a/source4/torture/raw/read.c b/source4/torture/raw/read.c index 12818f7ba6..fb2e2ddec2 100644 --- a/source4/torture/raw/read.c +++ b/source4/torture/raw/read.c @@ -90,7 +90,7 @@ static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) const char *test_data = "TEST DATA"; uint_t seed = time(NULL); - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -214,7 +214,7 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) const char *test_data = "TEST DATA"; uint_t seed = time(NULL); - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -357,7 +357,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) const char *test_data = "TEST DATA"; uint_t seed = time(NULL); - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -551,7 +551,7 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) const char *test_data = "TEST DATA"; uint_t seed = time(NULL); - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c index 55acaba2b2..84466d0cde 100644 --- a/source4/torture/raw/search.c +++ b/source4/torture/raw/search.c @@ -960,9 +960,9 @@ static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) smbcli_close(cli->tree, fnum); } - file = talloc_zero_array_p(mem_ctx, union smb_search_data, num_dirs); - file2 = talloc_zero_array_p(mem_ctx, union smb_search_data, num_dirs); - file3 = talloc_zero_array_p(mem_ctx, union smb_search_data, num_dirs); + file = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs); + file2 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs); + file3 = talloc_zero_array(mem_ctx, union smb_search_data, num_dirs); printf("Search first on %d dirs\n", num_dirs); diff --git a/source4/torture/raw/write.c b/source4/torture/raw/write.c index 06fbe667ea..698520258d 100644 --- a/source4/torture/raw/write.c +++ b/source4/torture/raw/write.c @@ -104,7 +104,7 @@ static BOOL test_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) uint_t seed = time(NULL); union smb_fileinfo finfo; - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -221,7 +221,7 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) uint_t seed = time(NULL); union smb_fileinfo finfo; - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -397,7 +397,7 @@ static BOOL test_writeunlock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) uint_t seed = time(NULL); union smb_fileinfo finfo; - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -534,7 +534,7 @@ static BOOL test_writeclose(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) uint_t seed = time(NULL); union smb_fileinfo finfo; - buf = talloc_zero(mem_ctx, maxsize); + buf = talloc_zero_size(mem_ctx, maxsize); if (!torture_setup_dir(cli, BASEDIR)) { return False; diff --git a/source4/torture/rpc/samsync.c b/source4/torture/rpc/samsync.c index 86e10678c9..4c47870015 100644 --- a/source4/torture/rpc/samsync.c +++ b/source4/torture/rpc/samsync.c @@ -878,7 +878,7 @@ static BOOL samsync_handle_account(TALLOC_CTX *mem_ctx, struct samsync_state *sa TEST_SEC_DESC_EQUAL(account->sdbuf, lsa, &acct_handle); - found_priv_in_lsa = talloc_zero_array_p(mem_ctx, BOOL, account->privilege_entries); + found_priv_in_lsa = talloc_zero_array(mem_ctx, BOOL, account->privilege_entries); e.in.handle = &acct_handle; diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c index 14c18df370..9e24a9f055 100644 --- a/source4/torture/rpc/winreg.c +++ b/source4/torture/rpc/winreg.c @@ -367,7 +367,7 @@ static BOOL test_QueryMultipleValues(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, r.in.num_values = 1; r.in.buffer_size = r.out.buffer_size = talloc_p(mem_ctx, uint32); *r.in.buffer_size = 0x20; - r.in.buffer = r.out.buffer = talloc_zero_array_p(mem_ctx, uint8, *r.in.buffer_size); + r.in.buffer = r.out.buffer = talloc_zero_array(mem_ctx, uint8, *r.in.buffer_size); status = dcerpc_winreg_QueryMultipleValues(p, mem_ctx, &r); if(NT_STATUS_IS_ERR(status)) { diff --git a/source4/utils/ndrdump.c b/source4/utils/ndrdump.c index c5867f85f1..1b80ea1825 100644 --- a/source4/utils/ndrdump.c +++ b/source4/utils/ndrdump.c @@ -146,7 +146,7 @@ static void show_functions(const struct dcerpc_interface_table *p) mem_ctx = talloc_init("ndrdump"); - st = talloc_zero(mem_ctx, f->struct_size); + st = talloc_zero_size(mem_ctx, f->struct_size); if (!st) { printf("Unable to allocate %d bytes\n", f->struct_size); exit(1); |