]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 398: Overlapping memcpy
authorTim Kientzle <kientzle@acm.org>
Sat, 7 Feb 2015 07:00:30 +0000 (23:00 -0800)
committerTim Kientzle <kientzle@acm.org>
Sat, 7 Feb 2015 07:00:30 +0000 (23:00 -0800)
Some of the pathname edits parse a part of the pathname
in the entry, then try to set the pathname from that part.
This leads the text routines to memcpy() from within the
string buffer.

Avoid this by simply using memmove() for low-level string append
operations.

CMakeLists.txt
configure.ac
libarchive/archive_string.c

index a9d2531e21908bbff9bc3d836e3733b49ba06eba..6e8ea374d6d5bc74c61a76d101498995b8cf34ac 100644 (file)
@@ -1219,6 +1219,7 @@ CHECK_FUNCTION_EXISTS(strftime HAVE_STRFTIME)
 CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF)
 CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP)
 CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY)
+CHECK_FUNCTION_EXISTS(wmemmove HAVE_WMEMMOVE)
 
 CMAKE_POP_CHECK_STATE()        # Restore the state of the variables
 
index 09e505c399d1e26fc353a4b35110608241ea3108..739cb0209e5b6707c4be3fb53d48a1cb5f61b8d6 100644 (file)
@@ -585,7 +585,7 @@ 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 unsetenv utime utimensat utimes vfork])
-AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy])
+AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy wmemmove])
 AC_CHECK_FUNCS([_ctime64_s _fseeki64])
 AC_CHECK_FUNCS([_get_timezone _localtime64_s _mkgmtime64])
 # detects cygwin-1.7, as opposed to older versions
index eebd7642bec14163d6a058bb5b0c6df31b2688a6..5bd81a0387882364f78e2d02a0ced89c21a95cbf 100644 (file)
@@ -71,6 +71,10 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33
 #define wmemcpy(a,b,i)  (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t))
 #endif
 
+#if !defined(HAVE_WMEMMOVE) && !defined(wmemmove)
+#define wmemmove(a,b,i)  (wchar_t *)memmove((a), (b), (i) * sizeof(wchar_t))
+#endif
+
 struct archive_string_conv {
        struct archive_string_conv      *next;
        char                            *from_charset;
@@ -203,7 +207,7 @@ archive_string_append(struct archive_string *as, const char *p, size_t s)
 {
        if (archive_string_ensure(as, as->length + s + 1) == NULL)
                return (NULL);
-       memcpy(as->s + as->length, p, s);
+       memmove(as->s + as->length, p, s);
        as->length += s;
        as->s[as->length] = 0;
        return (as);
@@ -214,7 +218,7 @@ archive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s)
 {
        if (archive_wstring_ensure(as, as->length + s + 1) == NULL)
                return (NULL);
-       wmemcpy(as->s + as->length, p, s);
+       wmemmove(as->s + as->length, p, s);
        as->length += s;
        as->s[as->length] = 0;
        return (as);