Show
Ignore:
Timestamp:
07/03/08 16:40:06 (5 months ago)
Author:
hailfinger
Message:

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 <c-d.hailfinger.devel.2006@…>
Acked-by: Stefan Reinauer <stepan@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/flashrom/layout.c

    r3367 r3408  
    2222#include <stdlib.h> 
    2323#include <string.h> 
     24#include <ctype.h> 
    2425#include <stdint.h> 
    2526#include "flash.h" 
     
    5859        } 
    5960 
    60         if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) { 
     61        /* 
     62         * Check if coreboot last image size is 0 or not a multiple of 1k or 
     63         * bigger than the chip or if the pointers to vendor ID or mainboard ID 
     64         * are outside the image of if the start of ID strings are nonsensical 
     65         * (nonprintable and not \0). 
     66         */ 
     67        if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || *walk > size || 
     68                *(walk - 1) > size || *(walk - 2) > size || 
     69                (!isprint((const char *)(bios + size - *(walk - 1))) && 
     70                ((const char *)(bios + size - *(walk - 1)))) || 
     71                (!isprint((const char *)(bios + size - *(walk - 2))) && 
     72                ((const char *)(bios + size - *(walk - 2))))) { 
    6173                printf("Flash image seems to be a legacy BIOS. Disabling checks.\n"); 
    6274                mainboard_vendor = def_name;