diff options
| author | Peter Marko <peter.marko@siemens.com> | 2025-11-23 23:40:23 +0100 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2025-12-01 06:50:49 -0800 |
| commit | 4030876db9a4c60ac09e498d5b4456822b476c76 (patch) | |
| tree | 1f4aad1ecdb2aaa9ecc918737125e3bca6f52738 /meta | |
| parent | c6234dce6342e9ba582f643e53ac348b5cdb0dab (diff) | |
| download | poky-4030876db9a4c60ac09e498d5b4456822b476c76.tar.gz | |
libarchive: patch 3.8.3 security issue 1
Pick patch [2] as listed in [1].
To apply it cleanly, add three additional patches from branch patch/3.8.
[1] https://github.com/libarchive/libarchive/releases/tag/v3.8.3
[2] https://github.com/libarchive/libarchive/pull/2753
(From OE-Core rev: 201eed780c73335c9278db17fe39fb453e16af08)
Signed-off-by: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'meta')
5 files changed, 435 insertions, 0 deletions
diff --git a/meta/recipes-extended/libarchive/libarchive/0001-Fix-max-path-length-metadata-writing-2243.patch b/meta/recipes-extended/libarchive/libarchive/0001-Fix-max-path-length-metadata-writing-2243.patch new file mode 100644 index 0000000000..0f7dca2a40 --- /dev/null +++ b/meta/recipes-extended/libarchive/libarchive/0001-Fix-max-path-length-metadata-writing-2243.patch | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | From 2e73ea3a7db1c3c743c28a0d2dd0456a43e96b96 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Sam Bingner <sam@bingner.com> | ||
| 3 | Date: Fri, 5 Jul 2024 09:34:43 -1000 | ||
| 4 | Subject: [PATCH] Fix max path-length metadata writing (#2243) | ||
| 5 | |||
| 6 | Previous code added `.XXXXXX` to the end of the filename to write the | ||
| 7 | mac metadata. This is a problem if the filename is at or near the | ||
| 8 | filesystem max path length. This reuses the same code used by | ||
| 9 | create_tempdatafork to ensure that the filename is not too long. | ||
| 10 | |||
| 11 | Upstream-Status: Backport [https://github.com/libarchive/libarchive/commit/2e73ea3a7db1c3c743c28a0d2dd0456a43e96b96] | ||
| 12 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
| 13 | --- | ||
| 14 | libarchive/archive_write_disk_posix.c | 3 +-- | ||
| 15 | 1 file changed, 1 insertion(+), 2 deletions(-) | ||
| 16 | |||
| 17 | diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c | ||
| 18 | index bac906d2..098a8fe4 100644 | ||
| 19 | --- a/libarchive/archive_write_disk_posix.c | ||
| 20 | +++ b/libarchive/archive_write_disk_posix.c | ||
| 21 | @@ -4331,8 +4331,7 @@ set_mac_metadata(struct archive_write_disk *a, const char *pathname, | ||
| 22 | * silly dance of writing the data to disk just so that | ||
| 23 | * copyfile() can read it back in again. */ | ||
| 24 | archive_string_init(&tmp); | ||
| 25 | - archive_strcpy(&tmp, pathname); | ||
| 26 | - archive_strcat(&tmp, ".XXXXXX"); | ||
| 27 | + archive_strcpy(&tmp, "tar.mmd.XXXXXX"); | ||
| 28 | fd = mkstemp(tmp.s); | ||
| 29 | |||
| 30 | if (fd < 0) { | ||
diff --git a/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2696-from-al3xtjames-mkstemp.patch b/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2696-from-al3xtjames-mkstemp.patch new file mode 100644 index 0000000000..a4ccfd16b5 --- /dev/null +++ b/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2696-from-al3xtjames-mkstemp.patch | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | From 53d2bc4f89fcbd7414b92bd242f6cdc901941f55 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tim Kientzle <kientzle@acm.org> | ||
| 3 | Date: Sat, 16 Aug 2025 10:27:11 -0600 | ||
| 4 | Subject: [PATCH] Merge pull request #2696 from al3xtjames/mkstemp | ||
| 5 | |||
| 6 | Fix mkstemp path in setup_mac_metadata | ||
| 7 | |||
| 8 | (cherry picked from commit 892f33145093d1c9b962b6521a6480dfea66ae00) | ||
| 9 | |||
| 10 | Upstream-Status: Backport [https://github.com/libarchive/libarchive/commit/53d2bc4f89fcbd7414b92bd242f6cdc901941f55] | ||
| 11 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
| 12 | --- | ||
| 13 | libarchive/archive_read_disk_entry_from_file.c | 2 +- | ||
| 14 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 15 | |||
| 16 | diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c | ||
| 17 | index 19d04977..87389642 100644 | ||
| 18 | --- a/libarchive/archive_read_disk_entry_from_file.c | ||
| 19 | +++ b/libarchive/archive_read_disk_entry_from_file.c | ||
| 20 | @@ -365,7 +365,7 @@ setup_mac_metadata(struct archive_read_disk *a, | ||
| 21 | tempdir = _PATH_TMP; | ||
| 22 | archive_string_init(&tempfile); | ||
| 23 | archive_strcpy(&tempfile, tempdir); | ||
| 24 | - archive_strcat(&tempfile, "tar.md.XXXXXX"); | ||
| 25 | + archive_strcat(&tempfile, "/tar.md.XXXXXX"); | ||
| 26 | tempfd = mkstemp(tempfile.s); | ||
| 27 | if (tempfd < 0) { | ||
| 28 | archive_set_error(&a->archive, errno, | ||
diff --git a/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2749-from-KlaraSystems-des-tempdi.patch b/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2749-from-KlaraSystems-des-tempdi.patch new file mode 100644 index 0000000000..0d69faa23b --- /dev/null +++ b/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2749-from-KlaraSystems-des-tempdi.patch | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | From 82e31ba4a9afcce0c7c19e591ccd8653196d84a0 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tim Kientzle <kientzle@acm.org> | ||
| 3 | Date: Mon, 13 Oct 2025 10:57:18 -0700 | ||
| 4 | Subject: [PATCH] Merge pull request #2749 from KlaraSystems/des/tempdir | ||
| 5 | |||
| 6 | Unify temporary directory handling | ||
| 7 | |||
| 8 | (cherry picked from commit d207d816d065c79dc2cb992008c3ba9721c6a276) | ||
| 9 | |||
| 10 | Upstream-Status: Backport [https://github.com/libarchive/libarchive/commit/82e31ba4a9afcce0c7c19e591ccd8653196d84a0] | ||
| 11 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
| 12 | --- | ||
| 13 | CMakeLists.txt | 6 ++- | ||
| 14 | configure.ac | 4 +- | ||
| 15 | libarchive/archive_private.h | 1 + | ||
| 16 | .../archive_read_disk_entry_from_file.c | 14 +++---- | ||
| 17 | libarchive/archive_read_disk_posix.c | 3 -- | ||
| 18 | libarchive/archive_util.c | 38 ++++++++++++++++--- | ||
| 19 | 6 files changed, 48 insertions(+), 18 deletions(-) | ||
| 20 | |||
| 21 | diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
| 22 | index f44adc77..fc9aca4e 100644 | ||
| 23 | --- a/CMakeLists.txt | ||
| 24 | +++ b/CMakeLists.txt | ||
| 25 | @@ -1357,14 +1357,18 @@ CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE) | ||
| 26 | CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS) | ||
| 27 | CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES) | ||
| 28 | CHECK_FUNCTION_EXISTS_GLIBC(futimesat HAVE_FUTIMESAT) | ||
| 29 | +CHECK_FUNCTION_EXISTS_GLIBC(getegid HAVE_GETEGID) | ||
| 30 | CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID) | ||
| 31 | CHECK_FUNCTION_EXISTS_GLIBC(getgrgid_r HAVE_GETGRGID_R) | ||
| 32 | CHECK_FUNCTION_EXISTS_GLIBC(getgrnam_r HAVE_GETGRNAM_R) | ||
| 33 | +CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) | ||
| 34 | CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R) | ||
| 35 | CHECK_FUNCTION_EXISTS_GLIBC(getpwuid_r HAVE_GETPWUID_R) | ||
| 36 | -CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) | ||
| 37 | +CHECK_FUNCTION_EXISTS_GLIBC(getresgid HAVE_GETRESGID) | ||
| 38 | +CHECK_FUNCTION_EXISTS_GLIBC(getresuid HAVE_GETRESUID) | ||
| 39 | CHECK_FUNCTION_EXISTS_GLIBC(getvfsbyname HAVE_GETVFSBYNAME) | ||
| 40 | CHECK_FUNCTION_EXISTS_GLIBC(gmtime_r HAVE_GMTIME_R) | ||
| 41 | +CHECK_FUNCTION_EXISTS_GLIBC(issetugid HAVE_ISSETUGID) | ||
| 42 | CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS) | ||
| 43 | CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD) | ||
| 44 | CHECK_FUNCTION_EXISTS_GLIBC(lchown HAVE_LCHOWN) | ||
| 45 | diff --git a/configure.ac b/configure.ac | ||
| 46 | index aae0f381..a1a8f380 100644 | ||
| 47 | --- a/configure.ac | ||
| 48 | +++ b/configure.ac | ||
| 49 | @@ -677,7 +677,9 @@ AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fcntl fdopendir fork]) | ||
| 50 | AC_CHECK_FUNCS([fstat fstatat fstatfs fstatvfs ftruncate]) | ||
| 51 | AC_CHECK_FUNCS([futimens futimes futimesat]) | ||
| 52 | AC_CHECK_FUNCS([geteuid getpid getgrgid_r getgrnam_r]) | ||
| 53 | -AC_CHECK_FUNCS([getpwnam_r getpwuid_r getvfsbyname gmtime_r]) | ||
| 54 | +AC_CHECK_FUNCS([getgrgid_r getgrnam_r getpwnam_r getpwuid_r]) | ||
| 55 | +AC_CHECK_FUNCS([getvfsbyname gmtime_r]) | ||
| 56 | +AC_CHECK_FUNCS([issetugid]) | ||
| 57 | AC_CHECK_FUNCS([lchflags lchmod lchown link linkat localtime_r lstat lutimes]) | ||
| 58 | AC_CHECK_FUNCS([mbrtowc memmove memset]) | ||
| 59 | AC_CHECK_FUNCS([mkdir mkfifo mknod mkstemp]) | ||
| 60 | diff --git a/libarchive/archive_private.h b/libarchive/archive_private.h | ||
| 61 | index 050fc63c..3a926c68 100644 | ||
| 62 | --- a/libarchive/archive_private.h | ||
| 63 | +++ b/libarchive/archive_private.h | ||
| 64 | @@ -156,6 +156,7 @@ int __archive_check_magic(struct archive *, unsigned int magic, | ||
| 65 | void __archive_errx(int retvalue, const char *msg) __LA_DEAD; | ||
| 66 | |||
| 67 | void __archive_ensure_cloexec_flag(int fd); | ||
| 68 | +int __archive_get_tempdir(struct archive_string *); | ||
| 69 | int __archive_mktemp(const char *tmpdir); | ||
| 70 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
| 71 | int __archive_mkstemp(wchar_t *template); | ||
| 72 | diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c | ||
| 73 | index 87389642..42af4034 100644 | ||
| 74 | --- a/libarchive/archive_read_disk_entry_from_file.c | ||
| 75 | +++ b/libarchive/archive_read_disk_entry_from_file.c | ||
| 76 | @@ -339,7 +339,7 @@ setup_mac_metadata(struct archive_read_disk *a, | ||
| 77 | int ret = ARCHIVE_OK; | ||
| 78 | void *buff = NULL; | ||
| 79 | int have_attrs; | ||
| 80 | - const char *name, *tempdir; | ||
| 81 | + const char *name; | ||
| 82 | struct archive_string tempfile; | ||
| 83 | |||
| 84 | (void)fd; /* UNUSED */ | ||
| 85 | @@ -358,14 +358,12 @@ setup_mac_metadata(struct archive_read_disk *a, | ||
| 86 | if (have_attrs == 0) | ||
| 87 | return (ARCHIVE_OK); | ||
| 88 | |||
| 89 | - tempdir = NULL; | ||
| 90 | - if (issetugid() == 0) | ||
| 91 | - tempdir = getenv("TMPDIR"); | ||
| 92 | - if (tempdir == NULL) | ||
| 93 | - tempdir = _PATH_TMP; | ||
| 94 | archive_string_init(&tempfile); | ||
| 95 | - archive_strcpy(&tempfile, tempdir); | ||
| 96 | - archive_strcat(&tempfile, "/tar.md.XXXXXX"); | ||
| 97 | + if (__archive_get_tempdir(&tempfile) != ARCHIVE_OK) { | ||
| 98 | + ret = ARCHIVE_WARN; | ||
| 99 | + goto cleanup; | ||
| 100 | + } | ||
| 101 | + archive_strcat(&tempfile, "tar.md.XXXXXX"); | ||
| 102 | tempfd = mkstemp(tempfile.s); | ||
| 103 | if (tempfd < 0) { | ||
| 104 | archive_set_error(&a->archive, errno, | ||
| 105 | diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c | ||
| 106 | index ba0046d7..54a8e661 100644 | ||
| 107 | --- a/libarchive/archive_read_disk_posix.c | ||
| 108 | +++ b/libarchive/archive_read_disk_posix.c | ||
| 109 | @@ -1579,9 +1579,6 @@ setup_current_filesystem(struct archive_read_disk *a) | ||
| 110 | # endif | ||
| 111 | #endif | ||
| 112 | int r, xr = 0; | ||
| 113 | -#if !defined(HAVE_STRUCT_STATFS_F_NAMEMAX) | ||
| 114 | - long nm; | ||
| 115 | -#endif | ||
| 116 | |||
| 117 | t->current_filesystem->synthetic = -1; | ||
| 118 | t->current_filesystem->remote = -1; | ||
| 119 | diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c | ||
| 120 | index 900abd0c..d048bbc9 100644 | ||
| 121 | --- a/libarchive/archive_util.c | ||
| 122 | +++ b/libarchive/archive_util.c | ||
| 123 | @@ -395,11 +395,39 @@ __archive_mkstemp(wchar_t *template) | ||
| 124 | #else | ||
| 125 | |||
| 126 | static int | ||
| 127 | -get_tempdir(struct archive_string *temppath) | ||
| 128 | +__archive_issetugid(void) | ||
| 129 | { | ||
| 130 | - const char *tmp; | ||
| 131 | +#ifdef HAVE_ISSETUGID | ||
| 132 | + return (issetugid()); | ||
| 133 | +#elif HAVE_GETRESUID | ||
| 134 | + uid_t ruid, euid, suid; | ||
| 135 | + gid_t rgid, egid, sgid; | ||
| 136 | + if (getresuid(&ruid, &euid, &suid) != 0) | ||
| 137 | + return (-1); | ||
| 138 | + if (ruid != euid || ruid != suid) | ||
| 139 | + return (1); | ||
| 140 | + if (getresgid(&ruid, &egid, &sgid) != 0) | ||
| 141 | + return (-1); | ||
| 142 | + if (rgid != egid || rgid != sgid) | ||
| 143 | + return (1); | ||
| 144 | +#elif HAVE_GETEUID | ||
| 145 | + if (geteuid() != getuid()) | ||
| 146 | + return (1); | ||
| 147 | +#if HAVE_GETEGID | ||
| 148 | + if (getegid() != getgid()) | ||
| 149 | + return (1); | ||
| 150 | +#endif | ||
| 151 | +#endif | ||
| 152 | + return (0); | ||
| 153 | +} | ||
| 154 | |||
| 155 | - tmp = getenv("TMPDIR"); | ||
| 156 | +int | ||
| 157 | +__archive_get_tempdir(struct archive_string *temppath) | ||
| 158 | +{ | ||
| 159 | + const char *tmp = NULL; | ||
| 160 | + | ||
| 161 | + if (__archive_issetugid() == 0) | ||
| 162 | + tmp = getenv("TMPDIR"); | ||
| 163 | if (tmp == NULL) | ||
| 164 | #ifdef _PATH_TMP | ||
| 165 | tmp = _PATH_TMP; | ||
| 166 | @@ -426,7 +454,7 @@ __archive_mktemp(const char *tmpdir) | ||
| 167 | |||
| 168 | archive_string_init(&temp_name); | ||
| 169 | if (tmpdir == NULL) { | ||
| 170 | - if (get_tempdir(&temp_name) != ARCHIVE_OK) | ||
| 171 | + if (__archive_get_tempdir(&temp_name) != ARCHIVE_OK) | ||
| 172 | goto exit_tmpfile; | ||
| 173 | } else { | ||
| 174 | archive_strcpy(&temp_name, tmpdir); | ||
| 175 | @@ -487,7 +515,7 @@ __archive_mktempx(const char *tmpdir, char *template) | ||
| 176 | if (template == NULL) { | ||
| 177 | archive_string_init(&temp_name); | ||
| 178 | if (tmpdir == NULL) { | ||
| 179 | - if (get_tempdir(&temp_name) != ARCHIVE_OK) | ||
| 180 | + if (__archive_get_tempdir(&temp_name) != ARCHIVE_OK) | ||
| 181 | goto exit_tmpfile; | ||
| 182 | } else | ||
| 183 | archive_strcpy(&temp_name, tmpdir); | ||
diff --git a/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2753-from-KlaraSystems-des-temp-f.patch b/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2753-from-KlaraSystems-des-temp-f.patch new file mode 100644 index 0000000000..a5efb3da94 --- /dev/null +++ b/meta/recipes-extended/libarchive/libarchive/0001-Merge-pull-request-2753-from-KlaraSystems-des-temp-f.patch | |||
| @@ -0,0 +1,190 @@ | |||
| 1 | From c3593848067cea3b41bc11eec15f391318675cb4 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tim Kientzle <kientzle@acm.org> | ||
| 3 | Date: Tue, 28 Oct 2025 17:13:18 -0700 | ||
| 4 | Subject: [PATCH] Merge pull request #2753 from KlaraSystems/des/temp-files | ||
| 5 | |||
| 6 | Create temporary files in the target directory | ||
| 7 | |||
| 8 | (cherry picked from commit d2e861769c25470427656b36a14b535f17d47d03) | ||
| 9 | |||
| 10 | Upstream-Status: Backport [https://github.com/libarchive/libarchive/commit/c3593848067cea3b41bc11eec15f391318675cb4] | ||
| 11 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
| 12 | --- | ||
| 13 | .../archive_read_disk_entry_from_file.c | 10 ++--- | ||
| 14 | libarchive/archive_string.c | 20 ++++++++++ | ||
| 15 | libarchive/archive_string.h | 4 ++ | ||
| 16 | libarchive/archive_write_disk_posix.c | 20 ++++++---- | ||
| 17 | libarchive/test/test_archive_string.c | 38 +++++++++++++++++++ | ||
| 18 | 5 files changed, 79 insertions(+), 13 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c | ||
| 21 | index 42af4034..121af198 100644 | ||
| 22 | --- a/libarchive/archive_read_disk_entry_from_file.c | ||
| 23 | +++ b/libarchive/archive_read_disk_entry_from_file.c | ||
| 24 | @@ -359,12 +359,10 @@ setup_mac_metadata(struct archive_read_disk *a, | ||
| 25 | return (ARCHIVE_OK); | ||
| 26 | |||
| 27 | archive_string_init(&tempfile); | ||
| 28 | - if (__archive_get_tempdir(&tempfile) != ARCHIVE_OK) { | ||
| 29 | - ret = ARCHIVE_WARN; | ||
| 30 | - goto cleanup; | ||
| 31 | - } | ||
| 32 | - archive_strcat(&tempfile, "tar.md.XXXXXX"); | ||
| 33 | - tempfd = mkstemp(tempfile.s); | ||
| 34 | + archive_strcpy(&tempfile, name); | ||
| 35 | + archive_string_dirname(&tempfile); | ||
| 36 | + archive_strcat(&tempfile, "/tar.XXXXXXXX"); | ||
| 37 | + tempfd = __archive_mkstemp(tempfile.s); | ||
| 38 | if (tempfd < 0) { | ||
| 39 | archive_set_error(&a->archive, errno, | ||
| 40 | "Could not open extended attribute file"); | ||
| 41 | diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c | ||
| 42 | index 3bb97833..740308b6 100644 | ||
| 43 | --- a/libarchive/archive_string.c | ||
| 44 | +++ b/libarchive/archive_string.c | ||
| 45 | @@ -2012,6 +2012,26 @@ archive_strncat_l(struct archive_string *as, const void *_p, size_t n, | ||
| 46 | return (r); | ||
| 47 | } | ||
| 48 | |||
| 49 | +struct archive_string * | ||
| 50 | +archive_string_dirname(struct archive_string *as) | ||
| 51 | +{ | ||
| 52 | + /* strip trailing separators */ | ||
| 53 | + while (as->length > 1 && as->s[as->length - 1] == '/') | ||
| 54 | + as->length--; | ||
| 55 | + /* strip final component */ | ||
| 56 | + while (as->length > 0 && as->s[as->length - 1] != '/') | ||
| 57 | + as->length--; | ||
| 58 | + /* empty path -> cwd */ | ||
| 59 | + if (as->length == 0) | ||
| 60 | + return (archive_strcat(as, ".")); | ||
| 61 | + /* strip separator(s) */ | ||
| 62 | + while (as->length > 1 && as->s[as->length - 1] == '/') | ||
| 63 | + as->length--; | ||
| 64 | + /* terminate */ | ||
| 65 | + as->s[as->length] = '\0'; | ||
| 66 | + return (as); | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | #if HAVE_ICONV | ||
| 70 | |||
| 71 | /* | ||
| 72 | diff --git a/libarchive/archive_string.h b/libarchive/archive_string.h | ||
| 73 | index e8987867..d5f5c03a 100644 | ||
| 74 | --- a/libarchive/archive_string.h | ||
| 75 | +++ b/libarchive/archive_string.h | ||
| 76 | @@ -195,6 +195,10 @@ void archive_string_vsprintf(struct archive_string *, const char *, | ||
| 77 | void archive_string_sprintf(struct archive_string *, const char *, ...) | ||
| 78 | __LA_PRINTF(2, 3); | ||
| 79 | |||
| 80 | +/* Equivalent to dirname(3) */ | ||
| 81 | +struct archive_string * | ||
| 82 | +archive_string_dirname(struct archive_string *); | ||
| 83 | + | ||
| 84 | /* Translates from MBS to Unicode. */ | ||
| 85 | /* Returns non-zero if conversion failed in any way. */ | ||
| 86 | int archive_wstring_append_from_mbs(struct archive_wstring *dest, | ||
| 87 | diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c | ||
| 88 | index 6fcf3929..cd256203 100644 | ||
| 89 | --- a/libarchive/archive_write_disk_posix.c | ||
| 90 | +++ b/libarchive/archive_write_disk_posix.c | ||
| 91 | @@ -412,12 +412,14 @@ static ssize_t _archive_write_disk_data_block(struct archive *, const void *, | ||
| 92 | static int | ||
| 93 | la_mktemp(struct archive_write_disk *a) | ||
| 94 | { | ||
| 95 | + struct archive_string *tmp = &a->_tmpname_data; | ||
| 96 | int oerrno, fd; | ||
| 97 | mode_t mode; | ||
| 98 | |||
| 99 | - archive_string_empty(&a->_tmpname_data); | ||
| 100 | - archive_string_sprintf(&a->_tmpname_data, "%s.XXXXXX", a->name); | ||
| 101 | - a->tmpname = a->_tmpname_data.s; | ||
| 102 | + archive_strcpy(tmp, a->name); | ||
| 103 | + archive_string_dirname(tmp); | ||
| 104 | + archive_strcat(tmp, "/tar.XXXXXXXX"); | ||
| 105 | + a->tmpname = tmp->s; | ||
| 106 | |||
| 107 | fd = __archive_mkstemp(a->tmpname); | ||
| 108 | if (fd == -1) | ||
| 109 | @@ -4251,8 +4253,10 @@ create_tempdatafork(struct archive_write_disk *a, const char *pathname) | ||
| 110 | int tmpfd; | ||
| 111 | |||
| 112 | archive_string_init(&tmpdatafork); | ||
| 113 | - archive_strcpy(&tmpdatafork, "tar.md.XXXXXX"); | ||
| 114 | - tmpfd = mkstemp(tmpdatafork.s); | ||
| 115 | + archive_strcpy(&tmpdatafork, pathname); | ||
| 116 | + archive_string_dirname(&tmpdatafork); | ||
| 117 | + archive_strcat(&tmpdatafork, "/tar.XXXXXXXX"); | ||
| 118 | + tmpfd = __archive_mkstemp(tmpdatafork.s); | ||
| 119 | if (tmpfd < 0) { | ||
| 120 | archive_set_error(&a->archive, errno, | ||
| 121 | "Failed to mkstemp"); | ||
| 122 | @@ -4331,8 +4335,10 @@ set_mac_metadata(struct archive_write_disk *a, const char *pathname, | ||
| 123 | * silly dance of writing the data to disk just so that | ||
| 124 | * copyfile() can read it back in again. */ | ||
| 125 | archive_string_init(&tmp); | ||
| 126 | - archive_strcpy(&tmp, "tar.mmd.XXXXXX"); | ||
| 127 | - fd = mkstemp(tmp.s); | ||
| 128 | + archive_strcpy(&tmp, pathname); | ||
| 129 | + archive_string_dirname(&tmp); | ||
| 130 | + archive_strcat(&tmp, "/tar.XXXXXXXX"); | ||
| 131 | + fd = __archive_mkstemp(tmp.s); | ||
| 132 | |||
| 133 | if (fd < 0) { | ||
| 134 | archive_set_error(&a->archive, errno, | ||
| 135 | diff --git a/libarchive/test/test_archive_string.c b/libarchive/test/test_archive_string.c | ||
| 136 | index 30f7a800..bf822c0d 100644 | ||
| 137 | --- a/libarchive/test/test_archive_string.c | ||
| 138 | +++ b/libarchive/test/test_archive_string.c | ||
| 139 | @@ -354,6 +354,43 @@ test_archive_string_sprintf(void) | ||
| 140 | archive_string_free(&s); | ||
| 141 | } | ||
| 142 | |||
| 143 | +static void | ||
| 144 | +test_archive_string_dirname(void) | ||
| 145 | +{ | ||
| 146 | + static struct pair { const char *str, *exp; } pairs[] = { | ||
| 147 | + { "", "." }, | ||
| 148 | + { "/", "/" }, | ||
| 149 | + { "//", "/" }, | ||
| 150 | + { "///", "/" }, | ||
| 151 | + { "./", "." }, | ||
| 152 | + { ".", "." }, | ||
| 153 | + { "..", "." }, | ||
| 154 | + { "foo", "." }, | ||
| 155 | + { "foo/", "." }, | ||
| 156 | + { "foo//", "." }, | ||
| 157 | + { "foo/bar", "foo" }, | ||
| 158 | + { "foo/bar/", "foo" }, | ||
| 159 | + { "foo/bar//", "foo" }, | ||
| 160 | + { "foo//bar", "foo" }, | ||
| 161 | + { "foo//bar/", "foo" }, | ||
| 162 | + { "foo//bar//", "foo" }, | ||
| 163 | + { "/foo", "/" }, | ||
| 164 | + { "//foo", "/" }, | ||
| 165 | + { "//foo/", "/" }, | ||
| 166 | + { "//foo//", "/" }, | ||
| 167 | + { 0 }, | ||
| 168 | + }; | ||
| 169 | + struct pair *pair; | ||
| 170 | + struct archive_string s; | ||
| 171 | + | ||
| 172 | + archive_string_init(&s); | ||
| 173 | + for (pair = pairs; pair->str; pair++) { | ||
| 174 | + archive_strcpy(&s, pair->str); | ||
| 175 | + archive_string_dirname(&s); | ||
| 176 | + assertEqualString(pair->exp, s.s); | ||
| 177 | + } | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | DEFINE_TEST(test_archive_string) | ||
| 181 | { | ||
| 182 | test_archive_string_ensure(); | ||
| 183 | @@ -365,6 +402,7 @@ DEFINE_TEST(test_archive_string) | ||
| 184 | test_archive_string_concat(); | ||
| 185 | test_archive_string_copy(); | ||
| 186 | test_archive_string_sprintf(); | ||
| 187 | + test_archive_string_dirname(); | ||
| 188 | } | ||
| 189 | |||
| 190 | static const char *strings[] = | ||
diff --git a/meta/recipes-extended/libarchive/libarchive_3.6.2.bb b/meta/recipes-extended/libarchive/libarchive_3.6.2.bb index 65b4649147..e0b8b15df4 100644 --- a/meta/recipes-extended/libarchive/libarchive_3.6.2.bb +++ b/meta/recipes-extended/libarchive/libarchive_3.6.2.bb | |||
| @@ -43,6 +43,10 @@ SRC_URI = "http://libarchive.org/downloads/libarchive-${PV}.tar.gz \ | |||
| 43 | file://0001-Improve-lseek-handling-2564.patch \ | 43 | file://0001-Improve-lseek-handling-2564.patch \ |
| 44 | file://CVE-2025-5918-01.patch \ | 44 | file://CVE-2025-5918-01.patch \ |
| 45 | file://CVE-2025-5918-02.patch \ | 45 | file://CVE-2025-5918-02.patch \ |
| 46 | file://0001-Fix-max-path-length-metadata-writing-2243.patch \ | ||
| 47 | file://0001-Merge-pull-request-2696-from-al3xtjames-mkstemp.patch \ | ||
| 48 | file://0001-Merge-pull-request-2749-from-KlaraSystems-des-tempdi.patch \ | ||
| 49 | file://0001-Merge-pull-request-2753-from-KlaraSystems-des-temp-f.patch \ | ||
| 46 | " | 50 | " |
| 47 | UPSTREAM_CHECK_URI = "http://libarchive.org/" | 51 | UPSTREAM_CHECK_URI = "http://libarchive.org/" |
| 48 | 52 | ||
