]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Add talloc_realloc_zero()
authorVolker Lendecke <vl@samba.org>
Tue, 29 Jul 2025 12:50:40 +0000 (14:50 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 2 Sep 2025 08:08:29 +0000 (08:08 +0000)
Like talloc_realloc, zeroing out expanded memory

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
lib/talloc/ABI/pytalloc-util-2.4.4.sigs [new file with mode: 0644]
lib/talloc/ABI/talloc-2.4.4.sigs [new file with mode: 0644]
lib/talloc/talloc.c
lib/talloc/talloc.h
lib/talloc/wscript

diff --git a/lib/talloc/ABI/pytalloc-util-2.4.4.sigs b/lib/talloc/ABI/pytalloc-util-2.4.4.sigs
new file mode 100644 (file)
index 0000000..6056577
--- /dev/null
@@ -0,0 +1,16 @@
+_pytalloc_check_type: int (PyObject *, const char *)
+_pytalloc_get_mem_ctx: TALLOC_CTX *(PyObject *)
+_pytalloc_get_name: const char *(PyObject *)
+_pytalloc_get_ptr: void *(PyObject *)
+_pytalloc_get_type: void *(PyObject *, const char *)
+pytalloc_BaseObject_PyType_Ready: int (PyTypeObject *)
+pytalloc_BaseObject_check: int (PyObject *)
+pytalloc_BaseObject_size: size_t (void)
+pytalloc_Check: int (PyObject *)
+pytalloc_GenericObject_reference_ex: PyObject *(TALLOC_CTX *, void *)
+pytalloc_GenericObject_steal_ex: PyObject *(TALLOC_CTX *, void *)
+pytalloc_GetBaseObjectType: PyTypeObject *(void)
+pytalloc_GetObjectType: PyTypeObject *(void)
+pytalloc_reference_ex: PyObject *(PyTypeObject *, TALLOC_CTX *, void *)
+pytalloc_steal: PyObject *(PyTypeObject *, void *)
+pytalloc_steal_ex: PyObject *(PyTypeObject *, TALLOC_CTX *, void *)
diff --git a/lib/talloc/ABI/talloc-2.4.4.sigs b/lib/talloc/ABI/talloc-2.4.4.sigs
new file mode 100644 (file)
index 0000000..7499ecb
--- /dev/null
@@ -0,0 +1,67 @@
+_talloc: void *(const void *, size_t)
+_talloc_array: void *(const void *, size_t, unsigned int, const char *)
+_talloc_free: int (void *, const char *)
+_talloc_get_type_abort: void *(const void *, const char *, const char *)
+_talloc_memdup: void *(const void *, const void *, size_t, const char *)
+_talloc_move: void *(const void *, const void *)
+_talloc_pooled_object: void *(const void *, size_t, const char *, unsigned int, size_t)
+_talloc_realloc: void *(const void *, void *, size_t, const char *)
+_talloc_realloc_array: void *(const void *, void *, size_t, unsigned int, const char *)
+_talloc_realloc_array_zero: void *(const void *, void *, size_t, unsigned int, const char *)
+_talloc_reference_loc: void *(const void *, const void *, const char *)
+_talloc_set_destructor: void (const void *, int (*)(void *))
+_talloc_steal_loc: void *(const void *, const void *, const char *)
+_talloc_zero: void *(const void *, size_t, const char *)
+_talloc_zero_array: void *(const void *, size_t, unsigned int, const char *)
+talloc_asprintf: char *(const void *, const char *, ...)
+talloc_asprintf_addbuf: void (char **, const char *, ...)
+talloc_asprintf_append: char *(char *, const char *, ...)
+talloc_asprintf_append_buffer: char *(char *, const char *, ...)
+talloc_autofree_context: void *(void)
+talloc_check_name: void *(const void *, const char *)
+talloc_disable_null_tracking: void (void)
+talloc_enable_leak_report: void (void)
+talloc_enable_leak_report_full: void (void)
+talloc_enable_null_tracking: void (void)
+talloc_enable_null_tracking_no_autofree: void (void)
+talloc_find_parent_byname: void *(const void *, const char *)
+talloc_free_children: void (void *)
+talloc_get_name: const char *(const void *)
+talloc_get_size: size_t (const void *)
+talloc_increase_ref_count: int (const void *)
+talloc_init: void *(const char *, ...)
+talloc_is_parent: int (const void *, const void *)
+talloc_named: void *(const void *, size_t, const char *, ...)
+talloc_named_const: void *(const void *, size_t, const char *)
+talloc_parent: void *(const void *)
+talloc_parent_name: const char *(const void *)
+talloc_pool: void *(const void *, size_t)
+talloc_realloc_fn: void *(const void *, void *, size_t)
+talloc_reference_count: size_t (const void *)
+talloc_reparent: void *(const void *, const void *, const void *)
+talloc_report: void (const void *, FILE *)
+talloc_report_depth_cb: void (const void *, int, int, void (*)(const void *, int, int, int, void *), void *)
+talloc_report_depth_file: void (const void *, int, int, FILE *)
+talloc_report_full: void (const void *, FILE *)
+talloc_set_abort_fn: void (void (*)(const char *))
+talloc_set_log_fn: void (void (*)(const char *))
+talloc_set_log_stderr: void (void)
+talloc_set_memlimit: int (const void *, size_t)
+talloc_set_name: const char *(const void *, const char *, ...)
+talloc_set_name_const: void (const void *, const char *)
+talloc_show_parents: void (const void *, FILE *)
+talloc_strdup: char *(const void *, const char *)
+talloc_strdup_append: char *(char *, const char *)
+talloc_strdup_append_buffer: char *(char *, const char *)
+talloc_strndup: char *(const void *, const char *, size_t)
+talloc_strndup_append: char *(char *, const char *, size_t)
+talloc_strndup_append_buffer: char *(char *, const char *, size_t)
+talloc_test_get_magic: int (void)
+talloc_total_blocks: size_t (const void *)
+talloc_total_size: size_t (const void *)
+talloc_unlink: int (const void *, void *)
+talloc_vasprintf: char *(const void *, const char *, va_list)
+talloc_vasprintf_append: char *(char *, const char *, va_list)
+talloc_vasprintf_append_buffer: char *(char *, const char *, va_list)
+talloc_version_major: int (void)
+talloc_version_minor: int (void)
index 727abe77a24620ac18d4afd3f7759c6e6ee94b22..ac3d26fcb52d7cbbfd860ce2bac0717549cfde47 100644 (file)
@@ -2810,6 +2810,39 @@ _PUBLIC_ void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size,
        return _talloc_realloc(ctx, ptr, el_size * count, name);
 }
 
+/*
+ * realloc an array, checking for integer overflow in the array size
+ * and zero out potential additional memory
+ */
+_PUBLIC_ void *_talloc_realloc_array_zero(const void *ctx,
+                                         void *ptr,
+                                         size_t el_size,
+                                         unsigned count,
+                                         const char *name)
+{
+       size_t existing, newsize;
+       void *newptr = NULL;
+
+       if (count >= MAX_TALLOC_SIZE / el_size) {
+               return NULL;
+       }
+
+       existing = talloc_get_size(ptr);
+       newsize = el_size * count;
+
+       newptr = _talloc_realloc(ctx, ptr, newsize, name);
+       if (newptr == NULL) {
+               return NULL;
+       }
+
+       if (newsize > existing) {
+               size_t to_zero = newsize - existing;
+               memset_s(((char *)newptr) + existing, to_zero, 0, to_zero);
+       }
+
+       return newptr;
+}
+
 /*
   a function version of talloc_realloc(), so it can be passed as a function pointer
   to libraries that want a realloc function (a realloc function encapsulates
index eef1a701b1f3b473fe537cf3f2e6bbca04b424e9..62142d188f1fbcef45b387249607f67e1304e7a2 100644 (file)
@@ -1296,6 +1296,39 @@ _PUBLIC_ void *talloc_realloc(const void *ctx, void *ptr, #type, size_t count);
 _PUBLIC_ void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
 #endif
 
+#ifdef DOXYGEN
+/**
+ * @brief Change the size of a talloc array, zero out additional space.
+ *
+ * Same as talloc_realloc() with the additional behavior to zero out
+ * code in case the array is expanded.
+ *
+ * @param[in]  ctx      The parent context used if ptr is NULL.
+ *
+ * @param[in]  ptr      The chunk to be resized.
+ *
+ * @param[in]  type     The type of the array element inside ptr.
+ *
+ * @param[in]  count    The intended number of array elements.
+ *
+ * @return              The new array, NULL on error. The call will fail either
+ *                      due to a lack of memory, or because the pointer has more
+ *                      than one parent (see talloc_reference()).
+ */
+_PUBLIC_ void *talloc_realloc_zero(const void *ctx,
+                                  void *ptr,
+                                  #type,
+                                  size_t count);
+#else
+#define talloc_realloc_zero(ctx, p, type, count) \
+       (type *)_talloc_realloc_array_zero(ctx, p, sizeof(type), count, #type)
+_PUBLIC_ void *_talloc_realloc_array_zero(const void *ctx,
+                                         void *ptr,
+                                         size_t el_size,
+                                         unsigned count,
+                                         const char *name);
+#endif
+
 #ifdef DOXYGEN
 /**
  * @brief Untyped realloc to change the size of a talloc array.
index b4b89ec19933fe7fb315f776a9880656db13f572..d36d3587480ed9d72d729475478b998d254faa2e 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 APPNAME = 'talloc'
-VERSION = '2.4.3'
+VERSION = '2.4.4'
 
 import os
 import sys