mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibIPC: Move most of DeprecatedString's encoder to StringView's encoder
This was a footgun waiting to happen. The StringView encoder is only used internally within IPC::Encoder to encode DeprecatedString. It does not encode its null state nor its length. If someone were to innocently use the StringView encoder as it is, and then decode a DeprecatedString on the remote end, the decoding would be corrupt. This changes the StringView encoder to do the work the DeprecatedString encoder is currently doing, and the latter now just forwards to it.
This commit is contained in:
parent
7c6b5ed161
commit
0ae2cef8b4
Notes:
sideshowbarker
2024-07-17 02:29:45 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/0ae2cef8b4 Pull-request: https://github.com/SerenityOS/serenity/pull/16817
|
@ -44,6 +44,11 @@ ErrorOr<void> encode(Encoder& encoder, double const& value)
|
|||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, StringView const& value)
|
||||
{
|
||||
// NOTE: Do not change this encoding without also updating LibC/netdb.cpp.
|
||||
if (value.is_null())
|
||||
return encoder.encode(NumericLimits<u32>::max());
|
||||
|
||||
TRY(encoder.encode_size(value.length()));
|
||||
TRY(encoder.append(reinterpret_cast<u8 const*>(value.characters_without_null_termination()), value.length()));
|
||||
return {};
|
||||
}
|
||||
|
@ -51,13 +56,7 @@ ErrorOr<void> encode(Encoder& encoder, StringView const& value)
|
|||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, DeprecatedString const& value)
|
||||
{
|
||||
// NOTE: Do not change this encoding without also updating LibC/netdb.cpp.
|
||||
if (value.is_null())
|
||||
return encoder.encode(NumericLimits<u32>::max());
|
||||
|
||||
TRY(encoder.encode_size(value.length()));
|
||||
TRY(encoder.encode(value.view()));
|
||||
return {};
|
||||
return encoder.encode(value.view());
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Reference in a new issue