[coreboot-gerrit] Change in coreboot[master]: util/amdfwtool/amdfwtool.c: Verify it actually read bytes

Richard Spiegel (Code Review) gerrit at coreboot.org
Wed Jan 17 18:25:16 CET 2018


Richard Spiegel has uploaded this change for review. ( https://review.coreboot.org/23304


Change subject: util/amdfwtool/amdfwtool.c: Verify it actually read bytes
......................................................................

util/amdfwtool/amdfwtool.c: Verify it actually read bytes

The function read() returns the number of bytes actually read. Program is
assuming it actually read the required number of bytes without checking.
This is wrong.

This fixes CIDs 1353019 and 1353021

BUG=b:72062481
TEST=Build no errors

Change-Id: I22d41b3de4eac5369f512f78b1b31cc1a250f787
Signed-off-by: Richard Spiegel <richard.spiegel at silverbackltd.com>
---
M util/amdfwtool/amdfwtool.c
1 file changed, 10 insertions(+), 6 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/04/23304/1

diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 4374c73..ce89d77 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -284,7 +284,7 @@
 static uint32_t integrate_firmwares(char *base, uint32_t pos, uint32_t *romsig,
 				    amd_fw_entry *fw_table, uint32_t rom_size)
 {
-	int fd;
+	int fd, bytes;
 	struct stat fd_stat;
 	int i;
 	uint32_t rom_base_address = 0xFFFFFFFF - rom_size + 1;
@@ -323,9 +323,11 @@
 				exit(1);
 			}
 
-			read(fd, (void *)(base + pos), (size_t)fd_stat.st_size);
+			bytes = read(fd, (void *)(base + pos),
+					(size_t)fd_stat.st_size);
+			if (bytes > 0)
+				pos += fd_stat.st_size;
 
-			pos += fd_stat.st_size;
 			close(fd);
 			pos = ALIGN(pos, 0x100U);
 		}
@@ -339,7 +341,7 @@
 					amd_fw_entry *fw_table,
 					uint32_t rom_size)
 {
-	int fd;
+	int fd, bytes;
 	struct stat fd_stat;
 	unsigned int i;
 	uint32_t rom_base_address = 0xFFFFFFFF - rom_size + 1;
@@ -378,9 +380,11 @@
 				exit(1);
 			}
 
-			read(fd, (void *)(base + pos), (size_t)fd_stat.st_size);
+			bytes = read(fd, (void *)(base + pos),
+					(size_t)fd_stat.st_size);
+			if (bytes > 0)
+				pos += fd_stat.st_size;
 
-			pos += fd_stat.st_size;
 			close(fd);
 			pos = ALIGN(pos, 0x100U);
 		} else {

-- 
To view, visit https://review.coreboot.org/23304
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22d41b3de4eac5369f512f78b1b31cc1a250f787
Gerrit-Change-Number: 23304
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Spiegel <richard.spiegel at silverbackltd.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180117/f9da8ec5/attachment.html>


More information about the coreboot-gerrit mailing list