ACK: [PATCH] fwts_coreboot_cbmem: fix off-by-one error on last char of buffer

Alex Hung alex.hung at canonical.com
Tue Aug 14 19:14:01 UTC 2018


On 2018-08-14 06:16 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> The coreboot_log has been allocated a size of console->size + 1,
> however, the end of string terminator '\0' is being written one
> character passed the end of the buffer because of an off-by-one
> error. Fix this.
> 
> Also insert some spaces as per the fwts coding style.
> 
> Detected by CoverityScan, CID#1394472 ("Out-of-bounds write")
> 
> Fixes: c9bf07f25d13 ("fwts_coreboot.c: add cbmem console parser")
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/src/fwts_coreboot_cbmem.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
> index 456ac694..52f83f47 100644
> --- a/src/lib/src/fwts_coreboot_cbmem.c
> +++ b/src/lib/src/fwts_coreboot_cbmem.c
> @@ -334,13 +334,13 @@ char *fwts_coreboot_cbmem_console_dump(void)
>   
>   	free(console_p);
>   
> -	coreboot_log = malloc(console->size+1);
> +	coreboot_log = malloc(console->size + 1);
>   	if (!coreboot_log) {
>   		free(console);
>   		return NULL;
>   	}
>   
> -	coreboot_log[console->size + 1] = '\0';
> +	coreboot_log[console->size] = '\0';
>   
>   	count = memconsole_coreboot_read(console, coreboot_log, 0, console->size);
>   	free(console);
> 

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list