From: Joerg Sonnenberger Date: Tue, 1 Aug 2017 15:17:45 +0000 (+0200) Subject: Don't call wmemmove if size is zero. X-Git-Tag: v3.3.3~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d5e5f32208a42fc3e7986645a791524939aa9e4;p=thirdparty%2Flibarchive.git Don't call wmemmove if size is zero. The data pointers can be NULL in this case and ISO C says this is UB. --- diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index 5ae09b626..392cc1103 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33 * without incurring additional memory allocations. */ +#include #ifdef HAVE_ERRNO_H #include #endif @@ -214,7 +215,9 @@ archive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s) { if (archive_wstring_ensure(as, as->length + s + 1) == NULL) return (NULL); - wmemmove(as->s + as->length, p, s); + assert(p != NULL); + if (s) + wmemmove(as->s + as->length, p, s); as->length += s; as->s[as->length] = 0; return (as);