From 039b8480664d8b709b7d5806b627e6f876afdb67 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Thu, 3 Jul 2008 14:40:06 +0000 Subject: Improve coreboot image detection heuristic in flashrom. It's not absolutely perfect, but the likelihood of this check to fail is 0.000000000000000000000000013 (1.3*10^-26) which is good enough for me. Signed-off-by: Carl-Daniel Hailfinger Acked-by: Stefan Reinauer git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3408 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- util/flashrom/layout.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'util/flashrom') diff --git a/util/flashrom/layout.c b/util/flashrom/layout.c index a738fb22d5..f41e0ea364 100644 --- a/util/flashrom/layout.c +++ b/util/flashrom/layout.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "flash.h" @@ -57,7 +58,18 @@ int show_id(uint8_t *bios, int size, int force) walk--; } - if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) { + /* + * Check if coreboot last image size is 0 or not a multiple of 1k or + * bigger than the chip or if the pointers to vendor ID or mainboard ID + * are outside the image of if the start of ID strings are nonsensical + * (nonprintable and not \0). + */ + if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || *walk > size || + *(walk - 1) > size || *(walk - 2) > size || + (!isprint((const char *)(bios + size - *(walk - 1))) && + ((const char *)(bios + size - *(walk - 1)))) || + (!isprint((const char *)(bios + size - *(walk - 2))) && + ((const char *)(bios + size - *(walk - 2))))) { printf("Flash image seems to be a legacy BIOS. Disabling checks.\n"); mainboard_vendor = def_name; mainboard_part = def_name; -- cgit v1.2.3