[Intel-gfx] [PATCH i-g-t 2/2] intel_bios_reader: Don't explode looking for the devid

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Wed Mar 25 11:36:33 PDT 2015


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Check that the offset where expect to find the device id is withing the
BIOS image, instead of accessing whatever (if anything) happens to be
there.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 tools/intel_bios_reader.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/intel_bios_reader.c b/tools/intel_bios_reader.c
index 641cb38..c5fc777 100644
--- a/tools/intel_bios_reader.c
+++ b/tools/intel_bios_reader.c
@@ -1052,11 +1052,14 @@ err:
 
 
 static int
-get_device_id(unsigned char *bios)
+get_device_id(unsigned char *bios, int size)
 {
     int device;
     int offset = (bios[0x19] << 8) + bios[0x18];
 
+    if (offset + 7 >= size)
+	return -1;
+
     if (bios[offset] != 'P' ||
 	bios[offset+1] != 'C' ||
 	bios[offset+2] != 'I' ||
@@ -1296,7 +1299,7 @@ int main(int argc, char **argv)
 	printf("\n");
 
 	if (devid == -1)
-	    devid = get_device_id(VBIOS);
+	    devid = get_device_id(VBIOS, size);
 	if (devid == -1)
 	    printf("Warning: could not find PCI device ID!\n");
 
-- 
2.0.5



More information about the Intel-gfx mailing list