efi_loader: fix get_last_capsule()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 9 Feb 2021 19:20:34 +0000 (20:20 +0100)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 14 Feb 2021 09:34:15 +0000 (10:34 +0100)
commit15bbcafab1cb35614cd8d6fa52f0e90a894c1af5
tree6702222e4ea9e8e403bd430a629381d227a28d7c
parent841f7a4ebbe76c7843a864a5f9ca8f5f95a23df8
efi_loader: fix get_last_capsule()

fix get_last_capsule() leads to writes beyond the stack allocated buffer.
This was indicated when enabling the stack protector.

utf16_utf8_strcpy() only stops copying when reaching '\0'. The current
invocation always writes beyond the end of value[].

The output length of utf16_utf8_strcpy() may be longer than the number of
UTF-16 tokens. E.g has "CapsuleКиев" has 11 UTF-16 tokens but 15 UTF-8
tokens. Hence, using utf16_utf8_strcpy() without checking the input may
lead to further writes beyond value[].

The current invocation of strict_strtoul() reads beyond the end of value[].

A non-hexadecimal value after "Capsule" (e.g. "CapsuleZZZZ") must result in
an error. We cat catch this by checking the return value of strict_strtoul().

A value that is too short after "Capsule" (e.g. "Capsule0") must result in
an error. We must check the string length of value[].

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
lib/efi_loader/efi_capsule.c