Browse code

bb#10848 - mbr: fixed a number of issues involving mbr parsing and scanning

Kevin Lin authored on 2014/03/27 04:44:01
Showing 2 changed files
... ...
@@ -1401,7 +1401,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1401 1401
 
1402 1402
 				    cli_dbgmsg("Matched signature for file type %s at %u\n", pt->virname, realoff);
1403 1403
 				    type = pt->type;
1404
-				    if(ftoffset && (!*ftoffset || (*ftoffset)->cnt < MAX_EMBEDDED_OBJ || type == CL_TYPE_ZIPSFX) && (type >= CL_TYPE_SFX || ((ftype == CL_TYPE_MSEXE || ftype == CL_TYPE_ZIP || ftype == CL_TYPE_MSOLE2) && type == CL_TYPE_MSEXE)))  {
1404
+				    if(ftoffset && (!*ftoffset || (*ftoffset)->cnt < MAX_EMBEDDED_OBJ || type == CL_TYPE_ZIPSFX) && (type == CL_TYPE_MBR || type >= CL_TYPE_SFX || ((ftype == CL_TYPE_MSEXE || ftype == CL_TYPE_ZIP || ftype == CL_TYPE_MSOLE2) && type == CL_TYPE_MSEXE)))  {
1405 1405
 
1406 1406
 					if(ac_addtype(ftoffset, type, realoff, ctx))
1407 1407
 					    return CL_EMEM;
... ...
@@ -128,6 +128,9 @@ int cli_mbr_check2(cli_ctx *ctx, size_t sectorsize) {
128 128
         return CL_EFORMAT;
129 129
     }
130 130
 
131
+    /* convert the little endian to host, include the internal  */
132
+    mbr_convert_to_host(&mbr);
133
+
131 134
     if ((mbr.entries[0].type == MBR_PROTECTIVE) || (mbr.entries[0].type == MBR_HYBRID))
132 135
         return CL_TYPE_GPT;
133 136
 
... ...
@@ -380,8 +383,8 @@ static int mbr_scanextprtn(cli_ctx *ctx, unsigned *prtncount, off_t extlba, size
380 380
 
381 381
                     partoff = (extlba + logiclba + ebr.entries[j].firstLBA) * sectorsize;
382 382
                     partsize = ebr.entries[j].numLBA * sectorsize;
383
-                    if (extoff + partsize > extsize) {
384
-                        cli_dbgmsg("cli_scanmbr: Invalid partition entry\n");
383
+                    if (partoff + partsize > extoff + extsize) {
384
+                        cli_dbgmsg("cli_scanebr: Invalid extended partition entry\n");
385 385
                         return CL_EFORMAT;
386 386
                     }
387 387