summaryrefslogtreecommitdiff
path: root/lib/talloc
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2018-11-22 16:10:39 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-12-12 18:34:10 +0100
commiteabe6d534c5c8c6ca38f3dc846f17aad6395da8c (patch)
tree6b948a3c136d4ba73e0d4181971e89210b2df080 /lib/talloc
parenta80fee5054db917050e0bda0482f8d17791d30dd (diff)
downloadsamba-eabe6d534c5c8c6ca38f3dc846f17aad6395da8c.tar.gz
lib:talloc: Fix undefined behavior in talloc_memdup
lib/talloc/talloc.c:2419: runtime error: null pointer passed as argument 2, which is declared to never be null Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib/talloc')
-rw-r--r--lib/talloc/talloc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 54be63495ae..073a3e50d4b 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -2413,9 +2413,14 @@ _PUBLIC_ void *_talloc_zero(const void *ctx, size_t size, const char *name)
*/
_PUBLIC_ void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name)
{
- void *newp = _talloc_named_const(t, size, name);
+ void *newp = NULL;
- if (likely(newp)) {
+ if (likely(size > 0) && unlikely(p == NULL)) {
+ return NULL;
+ }
+
+ newp = _talloc_named_const(t, size, name);
+ if (likely(newp != NULL) && likely(size > 0)) {
memcpy(newp, p, size);
}