From: Patrick Cheng Date: Wed, 20 Feb 2019 00:55:19 +0000 (-0800) Subject: calling strlen() with null pointer (#1142) X-Git-Tag: v3.4.0~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be92846ba46e1abc87482be74f74c2f54a3b9ad9;p=thirdparty%2Flibarchive.git calling strlen() with null pointer (#1142) clang analyzer found this issue. other archive_mstring_copy_* has the pattern: ``` if (xxx == NULL) { aes->aes_set = 0; return (0); } ``` archive_mstring_copy_utf8() didn't follow that pattern, so if NULL is passed in, it will call strlen(NULL). Noticed that archive_mstring_copy_wcs_len() doesn't follow the pattern either. Fixes #1142 --- diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index 554533ecb..7dd341ef2 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -4050,6 +4050,7 @@ archive_mstring_copy_utf8(struct archive_mstring *aes, const char *utf8) { if (utf8 == NULL) { aes->aes_set = 0; + return (0); } aes->aes_set = AES_SET_UTF8; archive_string_empty(&(aes->aes_mbs)); @@ -4064,6 +4065,7 @@ archive_mstring_copy_wcs_len(struct archive_mstring *aes, const wchar_t *wcs, { if (wcs == NULL) { aes->aes_set = 0; + return (0); } aes->aes_set = AES_SET_WCS; /* Only WCS form set. */ archive_string_empty(&(aes->aes_mbs));