mirror of
https://git.savannah.gnu.org/git/tar.git
synced 2026-08-18 23:36:04 +00:00
Use openat2 to jailify the extraction directory
This addresses CVE-2025-45582. * gnulib.modules: Add openat2. * src/misc.c (open_subdir): New static function. (fdbase_opendir): Use it. * src/tar.c (open_searchdir_how): New var, replacing and augmenting open_searchdir_flags. All uses changed. * tests/extrac31.at: New file. * tests/Makefile (TESTSUITE_AT), tests/testuite.at: Add it.
This commit is contained in:
@@ -111,7 +111,7 @@ idx_t archive_names;
|
||||
const char **archive_name_cursor;
|
||||
char const *index_file_name;
|
||||
int open_read_flags;
|
||||
int open_searchdir_flags;
|
||||
struct open_how open_searchdir_how;
|
||||
int fstatat_flags;
|
||||
int seek_option;
|
||||
bool unquote_option;
|
||||
@@ -2709,8 +2709,12 @@ decode_options (int argc, char **argv)
|
||||
#else
|
||||
int search_flags = O_SEARCH | noatime_flag;
|
||||
#endif
|
||||
open_searchdir_flags = (search_flags | O_BINARY | O_CLOEXEC | O_DIRECTORY
|
||||
| nofollow_flag);
|
||||
open_searchdir_how.flags = (search_flags | nofollow_flag
|
||||
| O_BINARY | O_CLOEXEC | O_DIRECTORY);
|
||||
if (!absolute_names_option
|
||||
&& (subcommand_option == EXTRACT_SUBCOMMAND
|
||||
|| subcommand_option == DIFF_SUBCOMMAND))
|
||||
open_searchdir_how.resolve = RESOLVE_BENEATH;
|
||||
}
|
||||
fstatat_flags = dereference_option ? 0 : AT_SYMLINK_NOFOLLOW;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user