diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-04-13 20:05:41 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-13 19:51:57 +0200 |
commit | 118d3810915c37439c4a0084bab687e81b6c82a1 (patch) | |
tree | 1429411937c5c5885fa4a2355e7dc7b521122871 /Userland/Libraries/LibArchive | |
parent | a9a90b1b58f2bd227df7fd2a681c5931b64459b7 (diff) | |
download | serenity-118d3810915c37439c4a0084bab687e81b6c82a1.zip |
LibArchive: Stop null-terminating StringView tar file header fields
Since 8209c2b5707db24a8552c6ce8f361f9c49804dec was added the requires
check for copy_characters_to_buffer matched StringViews as well, which
caused unexpected null bytes to be inserted for non null-terminated
fields.
Diffstat (limited to 'Userland/Libraries/LibArchive')
-rw-r--r-- | Userland/Libraries/LibArchive/Tar.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Userland/Libraries/LibArchive/Tar.h b/Userland/Libraries/LibArchive/Tar.h index f175b3a5e0..37f591ddb3 100644 --- a/Userland/Libraries/LibArchive/Tar.h +++ b/Userland/Libraries/LibArchive/Tar.h @@ -61,10 +61,11 @@ static StringView get_field_as_string_view(char const (&field)[N]) template<size_t N, class TSource> static void set_field(char (&field)[N], TSource&& source) { - if constexpr (requires { source.copy_characters_to_buffer(field, N); }) { - VERIFY(source.copy_characters_to_buffer(field, N)); - } else { + if constexpr (requires { source.characters_without_null_termination(); }) { memcpy(field, source.characters_without_null_termination(), min(N, source.length())); + } else { + auto success = source.copy_characters_to_buffer(field, N); + VERIFY(success); } } |