Skip to content

Commit 098c174

Browse files
sandumjacobxorptr
authored andcommitted
Fix buffer overread in payload info
update comment
1 parent 07bb42d commit 098c174

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

protocol/payload_info.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,20 @@ bool libhoth_payload_info(const uint8_t* image, size_t len,
6262
memset(payload_info->image_hash, 0, sizeof(payload_info->image_hash));
6363
return false;
6464
} else {
65+
// Check for integer overflow
66+
if (descr->descriptor_area_size <=
67+
sizeof(struct image_descriptor) + sizeof(struct hash_sha256)) {
68+
return false;
69+
}
70+
6571
uint32_t region_size = descr->region_count * sizeof(struct image_region);
72+
// Check for overread
73+
if (region_size >
74+
(descr->descriptor_area_size - sizeof(struct image_descriptor) -
75+
sizeof(struct hash_sha256))) {
76+
return false;
77+
}
78+
6679
struct hash_sha256* hash =
6780
(struct hash_sha256*)((uint8_t*)&descr->image_regions + region_size);
6881
memcpy(payload_info->image_hash, hash->hash, sizeof(hash->hash));

protocol/payload_info_test.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,28 @@ TEST(PayloadInfotest, payload_info_non_SHA256_hash_type) {
138138
EXPECT_FALSE(libhoth_payload_info(image, statbuf.st_size, &info));
139139

140140
(void)munmap(image, statbuf.st_size);
141-
}
141+
}
142+
143+
TEST(PayloadInfoTest, PayloadInfoFuzzRegression) {
144+
std::string data = std::string(
145+
"_IMGDSC_\035_\to\245\245IM\007\001\000\000GDS\360\360\360\360\360C_"
146+
"\to\245\245\267\267\342\342\342\342\342\342\342\267\267\267\267\267\267"
147+
"\267\267\245\245\245\245\245\245\245\251\345\034%"
148+
"\035\252\000\241\254\332\314\374\r\242\205\342\246\247\327Z\241\364\000"
149+
"\250\002\246\205\260I\002\023\255\201\277\247\247\006C\235\234\245\245"
150+
"\245\245\245\245\245\245\245\245\245\245\200\200\200\000\300^"
151+
"\000\246\270\356\027\265\035\000\245\245\245\245\245\003\003\003\245\035"
152+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035"
153+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035"
154+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035"
155+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\000\035\035\034"
156+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035"
157+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035"
158+
"\035\035\035\035\035\035\035\035~~~~"
159+
"\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035\035"
160+
"\035\035\035\035\035\035\035",
161+
279);
162+
struct payload_info info;
163+
EXPECT_FALSE(libhoth_payload_info(
164+
reinterpret_cast<const uint8_t*>(data.data()), data.size(), &info));
165+
}

0 commit comments

Comments
 (0)