[Skiboot] [PATCH 2/2] libflash: fix bug on reading truncated flash file

Cyril Bur cyril.bur at au1.ibm.com
Wed May 18 09:59:16 AEST 2016


On Tue, 17 May 2016 13:57:07 +1000
Stewart Smith <stewart at linux.vnet.ibm.com> wrote:

> If we had a truncated file where libflash would attempt to read past
> the end, instead of erroring out, we'd get stuck in an infinite loop.
> 
> Why? Because we weren't acknowledging that read() returns 0 on EOF.
> 
> Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>

Hmmm not that I didn't see this problem coming, we've thrown away the easy way
of reporting the short read back up... not that it really matters and if
you're doing a short read, odds are something is indeed wrong.

Nothing wrong with the patch obviously. 

Reviewed-by: Cyril Bur <cyril.bur at au1.ibm.com>

> ---
>  libflash/file.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libflash/file.c b/libflash/file.c
> index 72e2da9..478bc13 100644
> --- a/libflash/file.c
> +++ b/libflash/file.c
> @@ -72,7 +72,7 @@ static int file_read(struct blocklevel_device *bl, uint32_t pos, void *buf, uint
>  	while (count < len) {
>  		rc = read(file_data->fd, buf, len);
>  		/* errno should remain set */
> -		if (rc == -1)
> +		if (rc == -1 || rc == 0)
>  			return FLASH_ERR_BAD_READ;
>  
>  		count += rc;



More information about the Skiboot mailing list