From a576439f229df2338faae006b7f247d2be5511e2 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 8 Aug 2016 04:50:57 -0700 Subject: [PATCH] libobs/util: Fix possible null pointer dereference Never checks to see whether the source dstr is empty before copying, and will crash if empty. --- libobs/util/dstr.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libobs/util/dstr.h b/libobs/util/dstr.h index c367c09b9..a07ae1c98 100644 --- a/libobs/util/dstr.h +++ b/libobs/util/dstr.h @@ -237,9 +237,11 @@ static inline void dstr_copy_dstr(struct dstr *dst, const struct dstr *src) if (dst->array) dstr_free(dst); - dstr_ensure_capacity(dst, src->len + 1); - memcpy(dst->array, src->array, src->len + 1); - dst->len = src->len; + if (src->len) { + dstr_ensure_capacity(dst, src->len + 1); + memcpy(dst->array, src->array, src->len + 1); + dst->len = src->len; + } } static inline void dstr_reserve(struct dstr *dst, const size_t capacity)