public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] efi_loader: fix off-by-one bug in efi_get_variable
@ 2018-05-08 22:50 Ivan Gorinov
  2018-05-09  9:17 ` Alexander Graf
  2018-05-09 10:01 ` Heinrich Schuchardt
  0 siblings, 2 replies; 3+ messages in thread
From: Ivan Gorinov @ 2018-05-08 22:50 UTC (permalink / raw)
  To: u-boot

efi_get_variable() always stores an extra zero byte after the output data.
When the returned data size matches the output buffer size, the extra zero
byte is stored past the end of the output buffer.

Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>
---
 lib/efi_loader/efi_variable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 6c177da..d031338 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -68,11 +68,11 @@ static const char *hex2mem(u8 *mem, const char *hexstr, int count)
 	do {
 		int nibble;
 
-		*mem = 0;
-
 		if (!count || !*hexstr)
 			break;
 
+		*mem = 0;
+
 		nibble = hex(*hexstr);
 		if (nibble < 0)
 			break;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] efi_loader: fix off-by-one bug in efi_get_variable
  2018-05-08 22:50 [U-Boot] [PATCH] efi_loader: fix off-by-one bug in efi_get_variable Ivan Gorinov
@ 2018-05-09  9:17 ` Alexander Graf
  2018-05-09 10:01 ` Heinrich Schuchardt
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Graf @ 2018-05-09  9:17 UTC (permalink / raw)
  To: u-boot

On 05/09/2018 12:50 AM, Ivan Gorinov wrote:
> efi_get_variable() always stores an extra zero byte after the output data.
> When the returned data size matches the output buffer size, the extra zero
> byte is stored past the end of the output buffer.
>
> Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>

Thanks to the memset right above the loop we can just remove the *mem = 
0 line altogether, no?

Alex

> ---
>   lib/efi_loader/efi_variable.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> index 6c177da..d031338 100644
> --- a/lib/efi_loader/efi_variable.c
> +++ b/lib/efi_loader/efi_variable.c
> @@ -68,11 +68,11 @@ static const char *hex2mem(u8 *mem, const char *hexstr, int count)
>   	do {
>   		int nibble;
>   
> -		*mem = 0;
> -
>   		if (!count || !*hexstr)
>   			break;
>   
> +		*mem = 0;
> +
>   		nibble = hex(*hexstr);
>   		if (nibble < 0)
>   			break;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] efi_loader: fix off-by-one bug in efi_get_variable
  2018-05-08 22:50 [U-Boot] [PATCH] efi_loader: fix off-by-one bug in efi_get_variable Ivan Gorinov
  2018-05-09  9:17 ` Alexander Graf
@ 2018-05-09 10:01 ` Heinrich Schuchardt
  1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2018-05-09 10:01 UTC (permalink / raw)
  To: u-boot



On 05/09/2018 12:50 AM, Ivan Gorinov wrote:
> efi_get_variable() always stores an extra zero byte after the output data.
> When the returned data size matches the output buffer size, the extra zero
> byte is stored past the end of the output buffer.
> 
> Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>

Thanks for the patch.

There other issues we might want to fix:

If the blob has an uneven number of hexadecimal digits 2 N + 1 the 
function hex2mem is called with count = 2 N + 2. hex('\0') will return 
-1, hex2mem returns NULL, and the blob is happily considered as correct. 
We should create an error instead.

There is no need for the argument count at all as hexstr is '\0' terminated.

> ---
>   lib/efi_loader/efi_variable.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> index 6c177da..d031338 100644
> --- a/lib/efi_loader/efi_variable.c
> +++ b/lib/efi_loader/efi_variable.c
> @@ -68,11 +68,11 @@ static const char *hex2mem(u8 *mem, const char *hexstr, int count)
>   	do {
>   		int nibble;
>   
> -		*mem = 0;
> -
>   		if (!count || !*hexstr)
>   			break;
>   
> +		*mem = 0;
> +

Why should we have this line at all? We set *mem = nibble below.

Regards

Heinrich

>   		nibble = hex(*hexstr);
>   		if (nibble < 0)
>   			break;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-09 10:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-08 22:50 [U-Boot] [PATCH] efi_loader: fix off-by-one bug in efi_get_variable Ivan Gorinov
2018-05-09  9:17 ` Alexander Graf
2018-05-09 10:01 ` Heinrich Schuchardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox