]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
calling strlen() with null pointer (#1142)
authorPatrick Cheng <patcheng@users.noreply.github.com>
Wed, 20 Feb 2019 00:55:19 +0000 (16:55 -0800)
committerMartin Matuška <martin@matuska.org>
Wed, 20 Feb 2019 00:55:19 +0000 (01:55 +0100)
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

libarchive/archive_string.c

index 554533ecb91bd0266602c26a823b391d03c946a5..7dd341ef2da33db5c578190fe8b94174003d94f0 100644 (file)
@@ -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));