don't scan beyond end of CBFS
authorFlorian Zumbiehl <florz@florz.de>
Tue, 1 Nov 2011 19:17:11 +0000 (20:17 +0100)
committerPatrick Georgi <patrick@georgi-clan.de>
Wed, 2 Nov 2011 09:49:24 +0000 (10:49 +0100)
Change-Id: I66e535f77e513dbfa5fc906ecf288193af78ae62
Signed-off-by: Florian Zumbiehl <florz@florz.de>
Reviewed-on: http://review.coreboot.org/369
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
payloads/libpayload/libcbfs/cbfs_core.c
src/lib/cbfs_core.c

index 596fa3ff726764bc66cdea509f94c20deedd8cae..4bf755b0f81083472b9fccfd3dc2f2183bfee5af 100644 (file)
@@ -97,6 +97,7 @@ struct cbfs_file *cbfs_find(const char *name)
                data = (void*)phys_to_virt(romstart()) + ntohl(header->offset);
                dataend = (void*)phys_to_virt(romstart()) + ntohl(header->romsize);
        }
+       dataend -= ntohl(header->bootblocksize);
 
        int align = ntohl(header->align);
 
@@ -106,7 +107,7 @@ struct cbfs_file *cbfs_find(const char *name)
                if (memcmp(CBFS_FILE_MAGIC, file->magic, strlen(CBFS_FILE_MAGIC)) != 0) {
                        // no file header found. corruption?
                        // proceed in aligned steps to resynchronize
-                       LOG("No file header found at %p, searching for header\n", data);
+                       LOG("ERROR: No file header found at %p, attempting to recover by searching for header\n", data);
                        data = phys_to_virt(CBFS_ALIGN_UP(virt_to_phys(data), align));
                        continue;
                }
index 596fa3ff726764bc66cdea509f94c20deedd8cae..4bf755b0f81083472b9fccfd3dc2f2183bfee5af 100644 (file)
@@ -97,6 +97,7 @@ struct cbfs_file *cbfs_find(const char *name)
                data = (void*)phys_to_virt(romstart()) + ntohl(header->offset);
                dataend = (void*)phys_to_virt(romstart()) + ntohl(header->romsize);
        }
+       dataend -= ntohl(header->bootblocksize);
 
        int align = ntohl(header->align);
 
@@ -106,7 +107,7 @@ struct cbfs_file *cbfs_find(const char *name)
                if (memcmp(CBFS_FILE_MAGIC, file->magic, strlen(CBFS_FILE_MAGIC)) != 0) {
                        // no file header found. corruption?
                        // proceed in aligned steps to resynchronize
-                       LOG("No file header found at %p, searching for header\n", data);
+                       LOG("ERROR: No file header found at %p, attempting to recover by searching for header\n", data);
                        data = phys_to_virt(CBFS_ALIGN_UP(virt_to_phys(data), align));
                        continue;
                }