Browse code

check for secondary GPT validity if primary is valid fixed a minor bug in GPT parsing

Kevin Lin authored on 2014/01/28 00:39:19
Showing 1 changed files
... ...
@@ -222,7 +222,7 @@ static int gpt_validate_header(cli_ctx *ctx, struct gpt_header hdr, size_t secto
222 222
 
223 223
 int cli_scangpt(cli_ctx *ctx)
224 224
 {
225
-    struct gpt_header hdr;
225
+    struct gpt_header hdr, chdr;
226 226
     struct gpt_partition_entry gpe;
227 227
     int ret = 0, func_ret = 0;
228 228
     size_t sectorsize, maplen, part_size;
... ...
@@ -274,6 +274,15 @@ int cli_scangpt(cli_ctx *ctx)
274 274
             return CL_EFORMAT;
275 275
         }
276 276
     }
277
+    else {
278
+        /* check validity of secondary header; still using the primary */
279
+        if (fmap_readn(*ctx->fmap, &chdr, pos, sizeof(chdr)) != sizeof(chdr)) {
280
+            cli_dbgmsg("cli_scangpt: Invalid secondary GPT header\n");
281
+        }
282
+        else  if (gpt_validate_header(ctx, chdr, sectorsize)) {
283
+            cli_dbgmsg("cli_scangpt: Secondary GPT header is invalid\n");
284
+        }
285
+    }
277 286
 
278 287
     /* convert endian to host */
279 288
     hdr.signature = be64_to_host(hdr.signature);
... ...
@@ -343,7 +352,7 @@ int cli_scangpt(cli_ctx *ctx)
343 343
 
344 344
             /* send the partition to cli_map_scan */
345 345
             part_off = gpe.firstLBA * sectorsize;
346
-            part_size = (gpe.lastLBA - gpe.firstLBA) * sectorsize;
346
+            part_size = (gpe.lastLBA - gpe.firstLBA + 1) * sectorsize;
347 347
             ret = cli_map_scan(*ctx->fmap, part_off, part_size, ctx, CL_TYPE_PART_ANY);
348 348
             if (ret != CL_CLEAN) {
349 349
                 if ((ctx->options & CL_SCAN_ALLMATCHES) && (ret == CL_VIRUS)) {