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

Stewart Smith stewart at linux.vnet.ibm.com
Tue May 17 13:57:07 AEST 2016


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>
---
 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;
-- 
2.5.5



More information about the Skiboot mailing list