]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tar: Fix empty wide character string handling 3052/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 19 May 2026 19:16:24 +0000 (21:16 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 19 May 2026 19:19:31 +0000 (21:19 +0200)
Apply the same fix as done in commit
c246ec5d058a3f70a2d3fb765f92fe9db77b25df for non-wide character
strings.

Without this, empty strings lead to out of boundary read accesses.

Resolves #3046.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_write_set_format_gnutar.c
libarchive/archive_write_set_format_pax.c
libarchive/archive_write_set_format_ustar.c
libarchive/archive_write_set_format_v7tar.c

index b67007a631c095c3f6929f2520a7c1ac2aaba132..f2ba4a0db4dce097b7c8f33e902e7e9d30578e64 100644 (file)
@@ -321,7 +321,8 @@ archive_write_gnutar_header(struct archive_write *a,
                const wchar_t *wp;
 
                wp = archive_entry_pathname_w(entry);
-               if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+               if (wp != NULL && wp[0] != L'\0' &&
+                   wp[wcslen(wp) - 1] != L'/') {
                        struct archive_wstring ws;
 
                        archive_string_init(&ws);
index f3589d6859e3b2ef9726df93914ddf69190c75de..debd2c6bf3573a8a77714a7d71cdc5c83e708c73 100644 (file)
@@ -676,7 +676,8 @@ archive_write_pax_header(struct archive_write *a,
                        const wchar_t *wp;
 
                        wp = archive_entry_pathname_w(entry_original);
-                       if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+                       if (wp != NULL && wp[0] != L'\0' &&
+                           wp[wcslen(wp) - 1] != L'/') {
                                struct archive_wstring ws;
 
                                archive_string_init(&ws);
index 97724c1588b3642e023cce15c9acf94d5787e4d3..e84152ea18f5e69ed59978e12048b0d3b7e58fe5 100644 (file)
@@ -281,7 +281,8 @@ archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry)
                const wchar_t *wp;
 
                wp = archive_entry_pathname_w(entry);
-               if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+               if (wp != NULL && wp[0] != L'\0' &&
+                   wp[wcslen(wp) - 1] != L'/') {
                        struct archive_wstring ws;
 
                        archive_string_init(&ws);
index 37ba73a1320a080310a33041777d1be2e16b2459..91c5e8e42f0b1cbeeb1b92024b86e2067eb17937 100644 (file)
@@ -259,7 +259,8 @@ archive_write_v7tar_header(struct archive_write *a, struct archive_entry *entry)
                const wchar_t *wp;
 
                wp = archive_entry_pathname_w(entry);
-               if (wp != NULL && wp[wcslen(wp) -1] != L'/') {
+               if (wp != NULL && wp[0] != L'\0' &&
+                   wp[wcslen(wp) - 1] != L'/') {
                        struct archive_wstring ws;
 
                        archive_string_init(&ws);