mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
AK: Disallow returning of string literals for errors in kernel code
This code should not be used in the kernel - we should always propagate proper errno codes in case we need to return those to userland so it could decode it in a reasonable way.
This commit is contained in:
parent
56b799c556
commit
048fb2c204
5 changed files with 51 additions and 20 deletions
|
@ -15,18 +15,18 @@ namespace AK {
|
|||
ErrorOr<ByteBuffer> decode_hex(StringView input)
|
||||
{
|
||||
if ((input.length() % 2) != 0)
|
||||
return Error::from_string_literal("Hex string was not an even length");
|
||||
return Error::from_string_view_or_print_error_and_return_errno("Hex string was not an even length"sv, EINVAL);
|
||||
|
||||
auto output = TRY(ByteBuffer::create_zeroed(input.length() / 2));
|
||||
|
||||
for (size_t i = 0; i < input.length() / 2; ++i) {
|
||||
auto const c1 = decode_hex_digit(input[i * 2]);
|
||||
if (c1 >= 16)
|
||||
return Error::from_string_literal("Hex string contains invalid digit");
|
||||
return Error::from_string_view_or_print_error_and_return_errno("Hex string contains invalid digit"sv, EINVAL);
|
||||
|
||||
auto const c2 = decode_hex_digit(input[i * 2 + 1]);
|
||||
if (c2 >= 16)
|
||||
return Error::from_string_literal("Hex string contains invalid digit");
|
||||
return Error::from_string_view_or_print_error_and_return_errno("Hex string contains invalid digit"sv, EINVAL);
|
||||
|
||||
output[i] = (c1 << 4) + c2;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue