]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use built-in strnlen on platforms where not available
authorMartin Matuska <martin@matuska.org>
Tue, 8 Dec 2020 01:26:52 +0000 (02:26 +0100)
committerMartin Matuska <martin@matuska.org>
Tue, 8 Dec 2020 09:01:14 +0000 (10:01 +0100)
Fixes #1464

CMakeLists.txt
build/cmake/config.h.in
configure.ac
libarchive/archive_read_support_format_mtree.c

index ab3bcf1f7b640b28d574c9dfc6125358341aa7cc..9d8fc3c46dc0adda0da6ffb6f515fb06ea2e8cff 100644 (file)
@@ -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)
index 6d2fa746927c5934c531fe1858c65676f013c1b1..ff629f9ceb4aef2eb0e9c0b1b5b0ed665e59530a 100644 (file)
@@ -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
 
index 94df6081540571b8852ed2b2727e91103e133f18..cb823bd473a27b36b40d124fced6de07f3097eeb 100644 (file)
@@ -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])
index 127706d53b17b20b61b50bab22ac11e7254396ed..93ba2959a3c67de0dabae505be39deb228e44362 100644 (file)
@@ -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;