image: Check for return value fo image_read() in image_type_from_data()
This commit is contained in:
1 parent
3c1ab9934d
commit
c258289b74
1 file changed
+17
-16
+17
-16
@@ -511,40 +511,41 @@ static const char * image_types[] = {
|
|||||||
enum image_type image_type_from_data(struct image * image) {
|
enum image_type image_type_from_data(struct image * image) {
|
||||||
|
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
|
size_t size;
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
image_seek(image, 0);
|
image_seek(image, 0);
|
||||||
image_read(image, buf, sizeof(buf));
|
size = image_read(image, buf, sizeof(buf));
|
||||||
|
|
||||||
if ( memcmp(buf+52, "2NDAPE", 6) == 0 )
|
if ( size >= 58 && memcmp(buf+52, "2NDAPE", 6) == 0 )
|
||||||
return IMAGE_2ND;
|
return IMAGE_2ND;
|
||||||
else if ( memcmp(buf+20, "2ND", 3) == 0 )
|
else if ( size >= 23 && memcmp(buf+20, "2ND", 3) == 0 )
|
||||||
return IMAGE_2ND;
|
return IMAGE_2ND;
|
||||||
else if ( memcmp(buf+4, "NOLOScnd", 8) == 0 )
|
else if ( size >= 8 && memcmp(buf+4, "NOLOScnd", 8) == 0 )
|
||||||
return IMAGE_SECONDARY;
|
return IMAGE_SECONDARY;
|
||||||
else if ( memcmp(buf+20, "X-LOADER", 8) == 0 )
|
else if ( size >= 28 && memcmp(buf+20, "X-LOADER", 8) == 0 )
|
||||||
return IMAGE_XLOADER;
|
return IMAGE_XLOADER;
|
||||||
else if ( memcmp(buf+12, "NOLOXldr", 8) == 0 )
|
else if ( size >= 20 && memcmp(buf+12, "NOLOXldr", 8) == 0 )
|
||||||
return IMAGE_XLOADER;
|
return IMAGE_XLOADER;
|
||||||
else if ( memcmp(buf+4, "NOLOXldr", 8) == 0 )
|
else if ( size >= 12 && memcmp(buf+4, "NOLOXldr", 8) == 0 )
|
||||||
return IMAGE_2ND;
|
return IMAGE_2ND;
|
||||||
else if ( memcmp(buf+36, "\x18\x28\x6f\x01", 4) == 0 ) /* ARM Linux kernel magic number */
|
else if ( size >= 40 && memcmp(buf+36, "\x18\x28\x6f\x01", 4) == 0 ) /* ARM Linux kernel magic number */
|
||||||
return IMAGE_KERNEL;
|
return IMAGE_KERNEL;
|
||||||
else if ( memcmp(buf+1, "\x00\x00\xea", 3) == 0 ) /* ARM U-Boot - instruction branch */
|
else if ( size >= 4 && memcmp(buf+1, "\x00\x00\xea", 3) == 0 ) /* ARM U-Boot - instruction branch */
|
||||||
return IMAGE_KERNEL;
|
return IMAGE_KERNEL;
|
||||||
else if ( memcmp(buf, "UBI#", 4) == 0 ) /* UBI EC header */
|
else if ( size >= 4 && memcmp(buf, "UBI#", 4) == 0 ) /* UBI EC header */
|
||||||
return IMAGE_ROOTFS;
|
return IMAGE_ROOTFS;
|
||||||
else if ( memcmp(buf+510, "\x55\xaa", 2) == 0 ) /* FAT boot sector signature */
|
else if ( size >= 512 && memcmp(buf+510, "\x55\xaa", 2) == 0 ) /* FAT boot sector signature */
|
||||||
return IMAGE_MMC;
|
return IMAGE_MMC;
|
||||||
else if ( memcmp(buf, "\xb0\x00\x01\x03\x9d\x00\x00\x00", 8) == 0 )
|
else if ( size >= 8 && memcmp(buf, "\xb0\x00\x01\x03\x9d\x00\x00\x00", 8) == 0 )
|
||||||
return IMAGE_CMT_2ND;
|
return IMAGE_CMT_2ND;
|
||||||
else if ( memcmp(buf, "\xb1\x00\x00\x00\x82\x00\x00\x00", 8) == 0 )
|
else if ( size >= 8 && memcmp(buf, "\xb1\x00\x00\x00\x82\x00\x00\x00", 8) == 0 )
|
||||||
return IMAGE_CMT_ALGO;
|
return IMAGE_CMT_ALGO;
|
||||||
else if ( memcmp(buf, "\xb2\x00\x00\x01\x44\x00\x00\x00", 8) == 0 )
|
else if ( size >= 8 && memcmp(buf, "\xb2\x00\x00\x01\x44\x00\x00\x00", 8) == 0 )
|
||||||
return IMAGE_CMT_MCUSW;
|
return IMAGE_CMT_MCUSW;
|
||||||
else if ( memcmp(buf, "\x45\x3d\xcd\x28", 4) == 0 ) /* CRAMFS MAGIC */
|
else if ( size >= 4 && memcmp(buf, "\x45\x3d\xcd\x28", 4) == 0 ) /* CRAMFS MAGIC */
|
||||||
return IMAGE_INITFS;
|
return IMAGE_INITFS;
|
||||||
else if ( memcmp(buf, "\x85\x19", 2) == 0 ) { /* JFFS2 MAGIC */
|
else if ( size >= 2 && memcmp(buf, "\x85\x19", 2) == 0 ) { /* JFFS2 MAGIC */
|
||||||
if ( image->size < 0x300000 )
|
if ( image->size < 0x300000 )
|
||||||
return IMAGE_INITFS;
|
return IMAGE_INITFS;
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user