summaryrefslogtreecommitdiff
path: root/layout.c
diff options
context:
space:
mode:
authorstefanct <stefanct@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2013-09-23 15:32:25 +0000
committerstefanct <stefanct@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2013-09-23 15:32:25 +0000
commit1694aaca589ae801eac0155d0552c328ccb51ded (patch)
tree7e1ce5783126c9ebe77be91b646022a872fb36d6 /layout.c
parent92126a64473c8d659c2bbaa3fafe9d7951c9d42f (diff)
downloadflashrom-0.9.7.tar.gz
layout: Verify layout entries before building a new image using them.0.9.7
This fixes a SEGFAULT if a layout entry is included that addresses memory outside the current chip's address range. flashrom will only abort if the offending region(s) is/are included else it will just warn. It will print warnings for regions with negative or zero-length address ranges too, but it will only abort if they are included with -i/--image to reduce the potential of regressions. This is different to the patch committed to the development branch in r1751. Also, abort for non-write operations if a layout file is given because there is no layout support for non-write operations yet, and some reports show that users expect it to work at least for -r/--read. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/branches/0.9.7@1752 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/layout.c b/layout.c
index 1bd3152..6ad8bf3 100644
--- a/layout.c
+++ b/layout.c
@@ -30,8 +30,8 @@ static int romimages = 0;
#define MAX_ROMLAYOUT 32
typedef struct {
- unsigned int start;
- unsigned int end;
+ chipoff_t start;
+ chipoff_t end;
unsigned int included;
char name[256];
} romlayout_t;
@@ -217,7 +217,32 @@ romlayout_t *get_next_included_romentry(unsigned int start)
return best_entry;
}
-int handle_romentries(const struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents)
+/* Validate and - if needed - normalize layout entries. */
+int normalize_romentries(const struct flashctx *flash)
+{
+ chipsize_t total_size = flash->chip->total_size * 1024;
+ int ret = 0;
+
+ int i;
+ for (i = 0; i < romimages; i++) {
+ if (rom_entries[i].start >= total_size || rom_entries[i].end >= total_size) {
+ msg_gwarn("Warning: Address range of region \"%s\" exceeds the current chip's "
+ "address space.\n", rom_entries[i].name);
+ if (rom_entries[i].included)
+ ret = 1;
+ }
+ if (rom_entries[i].start > rom_entries[i].end) {
+ msg_gwarn("Warning: Size of the address range of region \"%s\" is not positive.\n",
+ rom_entries[i].name);
+ if (rom_entries[i].included)
+ ret = 1;
+ }
+ }
+
+ return ret;
+}
+
+int build_new_image(const struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents)
{
unsigned int start = 0;
romlayout_t *entry;