Skip to content

Commit

Permalink
tools/unpack: fix extraction of directories without read/list permiss…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
Gottox committed Aug 10, 2023
1 parent d2ffd84 commit 1eee394
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions tools/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ extract_directory(
int rv;
char cwd[PATH_MAX] = {0};
struct SqshDirectoryIterator *iter = NULL;
uint16_t mode = sqsh_file_permission(file);

if (getcwd(cwd, sizeof(cwd)) == NULL) {
print_err(rv = -errno, "getcwd", path_stack);
goto out;
}
rv = mkdir(filename, mode);
rv = mkdir(filename, 0700);
if (rv < 0 && errno != EEXIST) {
print_err(rv = -errno, "mkdir", path_stack);
goto out;
Expand Down Expand Up @@ -263,32 +262,33 @@ extract(const char *filename, struct SqshFile *file,
print_path(&new_path_stack, "\n", stderr);
}

if (type == SQSH_FILE_TYPE_DIRECTORY) {
rv = extract_directory(filename, file, &new_path_stack);
} else {
if (type != SQSH_FILE_TYPE_DIRECTORY) {
rv = unlink(filename);
if (rv < 0 && errno != ENOENT) {
print_err(rv = -errno, "unlink", path_stack);
goto out;
}
}

switch (type) {
case SQSH_FILE_TYPE_FILE:
rv = extract_file(filename, file, &new_path_stack);
break;
case SQSH_FILE_TYPE_SYMLINK:
rv = extract_symlink(filename, file, &new_path_stack);
break;
case SQSH_FILE_TYPE_BLOCK:
case SQSH_FILE_TYPE_CHAR:
case SQSH_FILE_TYPE_FIFO:
case SQSH_FILE_TYPE_SOCKET:
rv = extract_device(filename, file, &new_path_stack);
break;
default:
print_err(-EINVAL, "extract", &new_path_stack);
rv = -EINVAL;
}
switch (type) {
case SQSH_FILE_TYPE_DIRECTORY:
rv = extract_directory(filename, file, &new_path_stack);
break;
case SQSH_FILE_TYPE_FILE:
rv = extract_file(filename, file, &new_path_stack);
break;
case SQSH_FILE_TYPE_SYMLINK:
rv = extract_symlink(filename, file, &new_path_stack);
break;
case SQSH_FILE_TYPE_BLOCK:
case SQSH_FILE_TYPE_CHAR:
case SQSH_FILE_TYPE_FIFO:
case SQSH_FILE_TYPE_SOCKET:
rv = extract_device(filename, file, &new_path_stack);
break;
default:
print_err(-EINVAL, "extract", &new_path_stack);
rv = -EINVAL;
}
if (rv < 0) {
goto out;
Expand Down

0 comments on commit 1eee394

Please sign in to comment.