LibIPC: Add additional validation for decoded values
Also add upfront bounds checking for variant indices before entering the recursive template, allowing us to convert the template's fallback error into VERIFY_NOT_REACHED() since the index is now guaranteed to be valid when we enter the recursive decode.
This commit is contained in:
parent
838a0fcaa6
commit
b4cbd321d9
1 changed files with 4 additions and 1 deletions
|
|
@ -231,7 +231,8 @@ ErrorOr<T> decode_variant(Decoder& decoder, size_t index)
|
|||
|
||||
return decode_variant<T, Index + 1>(decoder, index);
|
||||
} else {
|
||||
return Error::from_string_literal("IPC decode: Invalid variant index");
|
||||
// Index was validated before calling decode_variant
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -241,6 +242,8 @@ template<Concepts::Variant T>
|
|||
ErrorOr<T> decode(Decoder& decoder)
|
||||
{
|
||||
auto index = TRY(decoder.decode<typename T::IndexType>());
|
||||
if (index >= TypeList<T>::size)
|
||||
return Error::from_string_literal("IPC decode: Invalid variant index");
|
||||
return Detail::decode_variant<T>(decoder, index);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue