app:aboot: Validate the contents of Best match DTB entry.

Check Best match DTB contents are not resulting in overshoot of DTB
contents present in Boot image.

Change-Id: I1cc2a9f822da23dac28e3f14da0493c443533a4c
CRs-Fixed: 974290
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 26ccd57..7e83bc3 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -1317,6 +1317,17 @@
 			return -1;
 		}
 
+		if(dt_entry.offset > (UINT_MAX - dt_entry.size)) {
+			dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n");
+			return -1;
+		}
+
+		/* Ensure we are not overshooting dt_size with the dt_entry selected */
+		if ((dt_entry.offset + dt_entry.size) > hdr->dt_size) {
+			dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n");
+			return -1;
+		}
+
 		if (is_gzip_package((unsigned char *)dt_table_offset + dt_entry.offset, dt_entry.size))
 		{
 			unsigned int compressed_size = 0;