From 48755d52700b0323b2ad75aa64ced8eb4197e59e Mon Sep 17 00:00:00 2001 From: "Enno T. Boland" Date: Sat, 7 Dec 2024 16:02:41 +0100 Subject: [PATCH] Merge pull request #299 from Gottox/fix/invalid-cross-device-link unpack: fix `Invalid cross-device link errors` --- tools/src/unpack.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/src/unpack.c b/tools/src/unpack.c index 613f8739..693323a9 100644 --- a/tools/src/unpack.c +++ b/tools/src/unpack.c @@ -48,6 +48,8 @@ typedef int (*extract_fn)( const char *, enum SqshFileType, const struct SqshFile *); +static const char *TMP_SUFFIX = "-XXXXXX"; + struct CxSemaphore file_descriptor_sem; size_t extracted_files = 0; bool do_chown = false; @@ -155,7 +157,7 @@ update_metadata_dir(const char *path, const struct SqshFile *file) { } struct ExtractFileData { - char tmp_filename[32]; + char *tmp_filename; char *path; }; @@ -168,6 +170,7 @@ extract_file_cleanup(struct ExtractFileData *data, FILE *stream) { fclose(stream); } free(data->path); + free(data->tmp_filename); free(data); } static void @@ -212,7 +215,15 @@ extract_file(const char *path, const struct SqshFile *file) { perror(path); goto out; } - strcpy(data->tmp_filename, ".sqsh-unpack-XXXXXX"); + + data->tmp_filename = calloc(1, strlen(path) + sizeof(TMP_SUFFIX)); + if (data->tmp_filename == NULL) { + rv = -errno; + perror(path); + goto out; + } + strcpy(data->tmp_filename, path); + strcat(data->tmp_filename, TMP_SUFFIX); rv = cx_semaphore_wait(&file_descriptor_sem); if (rv < 0) {