MFV r321673:

Sync libarchive with vendor.

Relevant vendor changes:
  PR #926: ensure ar strtab is null terminated

MFC after:	1 week
This commit is contained in:
Martin Matuska 2017-07-28 23:56:07 +00:00
commit a758cabb3f
2 changed files with 4 additions and 3 deletions

View File

@ -64,7 +64,7 @@ typedef struct {
} archive_crypto_ctx; } archive_crypto_ctx;
#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
#include <Bcrypt.h> #include <bcrypt.h>
/* Common in other bcrypt implementations, but missing from VS2008. */ /* Common in other bcrypt implementations, but missing from VS2008. */
#ifndef BCRYPT_SUCCESS #ifndef BCRYPT_SUCCESS

View File

@ -374,13 +374,14 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s)
return (ARCHIVE_WARN); return (ARCHIVE_WARN);
} }
ar->strtab = (char *)malloc(s); ar->strtab = (char *)malloc(s + 1);
if (ar->strtab == NULL) { if (ar->strtab == NULL) {
archive_set_error(&a->archive, ENOMEM, archive_set_error(&a->archive, ENOMEM,
"Can't allocate strtab buffer"); "Can't allocate strtab buffer");
return (ARCHIVE_FATAL); return (ARCHIVE_FATAL);
} }
strncpy(ar->strtab, buff, s); memcpy(ar->strtab, buff, s);
ar->strtab[s] = '\0';
ar->has_strtab = 1; ar->has_strtab = 1;
} }