diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | build/cmake/config.h.in | 3 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | libarchive/archive_read_support_format_mtree.c | 23 |
4 files changed, 28 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ab3bcf1f..9d8fc3c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1378,6 +1378,7 @@ CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR) CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP) CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR) CHECK_FUNCTION_EXISTS_GLIBC(strncpy_s HAVE_STRNCPY_S) +CHECK_FUNCTION_EXISTS_GLIBC(strnlen HAVE_STRNLEN) CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR) CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK) CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 6d2fa746..ff629f9c 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -959,6 +959,9 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the `strchr' function. */ #cmakedefine HAVE_STRCHR 1 +/* Define to 1 if you have the `strnlen' function. */ +#cmakedefine HAVE_STRNLEN 1 + /* Define to 1 if you have the `strdup' function. */ #cmakedefine HAVE_STRDUP 1 diff --git a/configure.ac b/configure.ac index 94df6081..cb823bd4 100644 --- a/configure.ac +++ b/configure.ac @@ -654,8 +654,8 @@ AC_CHECK_FUNCS([mkdir mkfifo mknod mkstemp]) AC_CHECK_FUNCS([nl_langinfo openat pipe poll posix_spawnp readlink readlinkat]) AC_CHECK_FUNCS([readpassphrase]) AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs]) -AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm]) -AC_CHECK_FUNCS([tzset unlinkat unsetenv utime utimensat utimes vfork]) +AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strnlen strrchr symlink]) +AC_CHECK_FUNCS([timegm tzset unlinkat unsetenv utime utimensat utimes vfork]) AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy wmemmove]) AC_CHECK_FUNCS([_ctime64_s _fseeki64]) AC_CHECK_FUNCS([_get_timezone _gmtime64_s _localtime64_s _mkgmtime64]) diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 127706d5..93ba2959 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -136,6 +136,9 @@ static int skip(struct archive_read *a); static int read_header(struct archive_read *, struct archive_entry *); static int64_t mtree_atol(char **, int base); +#ifndef HAVE_STRNLEN +static size_t mtree_strnlen(const char *, size_t); +#endif /* * There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them @@ -187,6 +190,24 @@ get_time_t_min(void) #endif } +#ifdef HAVE_STRNLEN +#define mtree_strnlen(a,b) strnlen(a,b) +#else +static size_t +mtree_strnlen(const char *p, size_t maxlen) +{ + size_t i; + + for (i = 0; i <= maxlen; i++) { + if (p[i] == 0) + break; + } + if (i > maxlen) + return (-1);/* invalid */ + return (i); +} +#endif + static int archive_read_format_mtree_options(struct archive_read *a, const char *key, const char *val) @@ -1540,7 +1561,7 @@ parse_digest(struct archive_read *a, struct archive_entry *entry, len *= 2; - if (strnlen(digest, len+1) != len) { + if (mtree_strnlen(digest, len+1) != len) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "incorrect digest length, ignoring"); return ARCHIVE_WARN; |