[coreboot-gerrit] New patch to review for coreboot: 87dbfda cbfs: Check return value of map() for error

Isaac Christensen (isaac.christensen@se-eng.com) gerrit at coreboot.org
Fri Aug 8 20:28:53 CEST 2014


Isaac Christensen (isaac.christensen at se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6537

-gerrit

commit 87dbfdada3fa8cebd16f2e0ef1a39df5b96675a5
Author: Julius Werner <jwerner at chromium.org>
Date:   Mon Oct 28 20:00:50 2013 -0700

    cbfs: Check return value of map() for error
    
    The CBFS core checks the result of a media->map() operation in multiple
    places for CBFS_MEDIA_INVALID_MAP_ADDRESS, suggesting that this is a
    valid response. However, it ironically fails to do so when actually
    mapping the CBFS file itself, which can fail on buffer-constrained
    systems since the size is much larger than when mapping metadata. This
    patch adds a check with an error message and a NULL pointer return for
    that case to make it easier to understand this condition.
    
    Change-Id: Icae3dd20d3d111cdfc4f2dc6397b52174349b140
    Signed-off-by: Julius Werner <jwerner at chromium.org>
    Reviewed-on: https://chromium-review.googlesource.com/174951
    Reviewed-by: Gabe Black <gabeblack at chromium.org>
    Reviewed-by: Hung-Te Lin <hungte at chromium.org>
    (cherry picked from commit 63f2c4465f9633a637186e69bc3862d5413106ac)
    Signed-off-by: Isaac Christensen <isaac.christensen at se-eng.com>
---
 src/lib/cbfs_core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/lib/cbfs_core.c b/src/lib/cbfs_core.c
index 7ef103b..30cb194 100644
--- a/src/lib/cbfs_core.c
+++ b/src/lib/cbfs_core.c
@@ -156,6 +156,11 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
 			file_ptr = media->map(media, offset,
 					      file_offset + file_len);
 			media->close(media);
+			if (file_ptr == CBFS_MEDIA_INVALID_MAP_ADDRESS) {
+				ERROR("ERROR: Mapping %s failed (insufficient "
+				      "buffer space?).\n", file_name);
+				return NULL;
+			}
 			return file_ptr;
 		} else {
 			DEBUG(" (unmatched file @0x%x: %s)\n", offset,



More information about the coreboot-gerrit mailing list