commit c298d40abe5830f758f6e1b5deefdc72474ac589 Author: Jacob Welsh AuthorDate: Sun Apr 21 03:14:52 2024 +0000 Commit: Jacob Welsh CommitDate: Sun Apr 21 03:14:52 2024 +0000 busybox/archival: deferred reindent diff --git a/base/busybox/archival/libarchive/data_extract_all.c b/base/busybox/archival/libarchive/data_extract_all.c index 9253e28..5e52911 100644 --- a/base/busybox/archival/libarchive/data_extract_all.c +++ b/base/busybox/archival/libarchive/data_extract_all.c @@ -71,33 +71,33 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) { /* Remove the entry if it exists */ - /* Is it hardlink? - * We encode hard links as regular files of size 0 with a symlink */ - if (S_ISREG(file_header->mode) - && file_header->link_target - && file_header->size == 0 - ) { - /* Ugly special case: - * tar cf t.tar hardlink1 hardlink2 hardlink1 - * results in this tarball structure: - * hardlink1 - * hardlink2 -> hardlink1 - * hardlink1 -> hardlink1 <== !!! - */ - if (strcmp(file_header->link_target, file_header->name) == 0) - goto ret; - } - /* Proceed with deleting */ - /* Note 1: here and later we assume the Linux behavior that unlink on a directory fails with EISDIR. BSDs and POSIX don't distinguish this from EPERM, while UFS on Solaris reportedly allows root to unlink even non-empty directories. Accomodating these would require some more complex sequence. - * Note 2: skipping the unlink when S_ISDIR(file_header->mode), as formerly done here, is not a valid substitute because it fails to replace an existing non-directory file. Although it doesn't seem to directly open a symlink attack due to the earlier path check. + /* Is it hardlink? + * We encode hard links as regular files of size 0 with a symlink */ + if (S_ISREG(file_header->mode) + && file_header->link_target + && file_header->size == 0 + ) { + /* Ugly special case: + * tar cf t.tar hardlink1 hardlink2 hardlink1 + * results in this tarball structure: + * hardlink1 + * hardlink2 -> hardlink1 + * hardlink1 -> hardlink1 <== !!! */ - if (unlink(file_header->name) == -1 - && errno != ENOENT - && !(errno == EISDIR && S_ISDIR(file_header->mode)) - ) { - bb_perror_msg_and_die("can't remove old file %s", - file_header->name); - } + if (strcmp(file_header->link_target, file_header->name) == 0) + goto ret; + } + /* Proceed with deleting */ + /* Note 1: here and later we assume the Linux behavior that unlink on a directory fails with EISDIR. BSDs and POSIX don't distinguish this from EPERM, while UFS on Solaris reportedly allows root to unlink even non-empty directories. Accomodating these would require some more complex sequence. + * Note 2: skipping the unlink when S_ISDIR(file_header->mode), as formerly done here, is not a valid substitute because it fails to replace an existing non-directory file. Although it doesn't seem to directly open a symlink attack due to the earlier path check. + */ + if (unlink(file_header->name) == -1 + && errno != ENOENT + && !(errno == EISDIR && S_ISDIR(file_header->mode)) + ) { + bb_perror_msg_and_die("can't remove old file %s", + file_header->name); + } } else if (archive_handle->ah_flags & (ARCHIVE_EXTRACT_NEWER | ARCHIVE_O_TRUNC)) { /* Both these modes require looking at the inode before we leap. */ @@ -111,19 +111,19 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) } else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) { /* Remove the existing entry if it's older than the extracted entry */ if (existing_sb.st_mtime >= file_header->mtime) { - if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) - && !S_ISDIR(file_header->mode) - ) { - bb_error_msg("%s not created: newer or " - "same age file exists", file_header->name); + if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) + && !S_ISDIR(file_header->mode) + ) { + bb_error_msg("%s not created: newer or " + "same age file exists", file_header->name); + } + data_skip(archive_handle); + goto ret; + } + else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) { + bb_perror_msg_and_die("can't remove old file %s", + file_header->name); } - data_skip(archive_handle); - goto ret; - } - else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) { - bb_perror_msg_and_die("can't remove old file %s", - file_header->name); - } } else { /* ARCHIVE_O_TRUNC mode */ /* A directory may naturally block the overwrite, but not all special file types will; especially do NOT try writing into a symlink, fifo or device node! */ if (!S_ISREG(existing_sb.st_mode) @@ -194,15 +194,15 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) case S_IFLNK: /* Symlink */ if (file_header->link_target) { - res = symlink(file_header->link_target, file_header->name); - if ((res == -1) - && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) - ) { - bb_perror_msg("can't create %slink " - "from %s to %s", "sym", - file_header->name, - file_header->link_target); - } + res = symlink(file_header->link_target, file_header->name); + if ((res == -1) + && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) + ) { + bb_perror_msg("can't create %slink " + "from %s to %s", "sym", + file_header->name, + file_header->link_target); + } } else { bb_perror_msg("inconsistent file header: " "symlink without target %s",