From 63796c9e89dee9f04bdc2c2c03fb5032c26ba827 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Tue, 17 May 2016 13:57:07 +1000 Subject: libflash: fix bug on reading truncated flash file 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 Reviewed-by: Cyril Bur --- libflash/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libflash') 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; -- cgit v1.1