cgptlib: cast 32bit to 64bit before multiplication
authorPatrick Georgi <pgeorgi@google.com>
Tue, 2 Aug 2016 15:07:58 +0000 (17:07 +0200)
committerchrome-bot <chrome-bot@chromium.org>
Wed, 3 Aug 2016 14:06:32 +0000 (07:06 -0700)
Coverity noted that multiplying two 32bit values happens in 32bit, while
the result is to be stored in an uint64_t.

BUG=none
BRANCH=none
TEST=none

Found-by: Coverity Scan #1353032, #1353033, 1353034
Change-Id: I8d0c5fe4feee066a81e8904c525dc836dd7a4fc6
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://chromium-review.googlesource.com/365391
Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
firmware/lib/gpt_misc.c

index 0bf0940..c9b7170 100644 (file)
@@ -57,7 +57,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
                        gptdata->gpt_drive_sectors,
                        gptdata->flags)) {
                primary_valid = 1;
-               uint64_t entries_bytes = primary_header->number_of_entries
+               uint64_t entries_bytes =
+                               (uint64_t)primary_header->number_of_entries
                                * primary_header->size_of_entry;
                uint64_t entries_sectors = entries_bytes
                                        / gptdata->sector_bytes;
@@ -90,7 +91,8 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
                        gptdata->gpt_drive_sectors,
                        gptdata->flags)) {
                secondary_valid = 1;
-               uint64_t entries_bytes = secondary_header->number_of_entries
+               uint64_t entries_bytes =
+                               (uint64_t)secondary_header->number_of_entries
                                * secondary_header->size_of_entry;
                uint64_t entries_sectors = entries_bytes
                                / gptdata->sector_bytes;
@@ -122,7 +124,8 @@ int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
 {
        int skip_primary = 0;
        GptHeader *header = (GptHeader *)gptdata->primary_header;
-       uint64_t entries_bytes = header->number_of_entries
+       uint64_t entries_bytes =
+                               (uint64_t)header->number_of_entries
                                * header->size_of_entry;
        uint64_t entries_sectors = entries_bytes / gptdata->sector_bytes;
        int ret = 1;