diff options
author | implicitfield <114500360+implicitfield@users.noreply.github.com> | 2022-11-11 18:31:45 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-11-13 17:37:26 -0700 |
commit | 58e9262ff1665123bc58b2c99efbbe7341e00f78 (patch) | |
tree | 4d1660f48e7817ed04f63f9e299c21973d69be92 /Userland/Utilities/tar.cpp | |
parent | c88d8a21cc0ccc9080479bdb7020441c0a6ded4f (diff) | |
download | serenity-58e9262ff1665123bc58b2c99efbbe7341e00f78.zip |
LibArchive: Make get_field_as_integral error out on non-octal input
Fixes this bug that was reported by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52493
Diffstat (limited to 'Userland/Utilities/tar.cpp')
-rw-r--r-- | Userland/Utilities/tar.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp index 0e952fb142..16c6852283 100644 --- a/Userland/Utilities/tar.cpp +++ b/Userland/Utilities/tar.cpp @@ -160,12 +160,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) String absolute_path = Core::File::absolute_path(filename); auto parent_path = LexicalPath(absolute_path).parent(); + auto header_mode_or_error = header.mode(); + if (header_mode_or_error.is_error()) + return header_mode_or_error.release_error(); + auto header_mode = header_mode_or_error.release_value(); + switch (header.type_flag()) { case Archive::TarFileType::NormalFile: case Archive::TarFileType::AlternateNormalFile: { MUST(Core::Directory::create(parent_path, Core::Directory::CreateDirectories::Yes)); - int fd = TRY(Core::System::open(absolute_path, O_CREAT | O_WRONLY, header.mode())); + int fd = TRY(Core::System::open(absolute_path, O_CREAT | O_WRONLY, header_mode)); Array<u8, buffer_size> buffer; size_t bytes_read; @@ -184,7 +189,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) case Archive::TarFileType::Directory: { MUST(Core::Directory::create(parent_path, Core::Directory::CreateDirectories::Yes)); - auto result_or_error = Core::System::mkdir(absolute_path, header.mode()); + auto result_or_error = Core::System::mkdir(absolute_path, header_mode); if (result_or_error.is_error() && result_or_error.error().code() != EEXIST) return result_or_error.error(); break; |