Skip to content

Commit

Permalink
Merge pull request #299 from Gottox/fix/invalid-cross-device-link
Browse files Browse the repository at this point in the history
unpack: fix `Invalid cross-device link errors`
  • Loading branch information
Gottox committed Dec 8, 2024
1 parent 5ca42e2 commit 48755d5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/src/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 48755d5

Please sign in to comment.