Skip to content

Commit 9e421ff

Browse files
authored
Merge pull request #69 from wolfSSL/manifest-aligned-fields
Sanity check for aligned fields in manifest header Fix confirmed (thanks @guidovranken !)
2 parents 12294df + b3f471b commit 9e421ff

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/libwolfboot.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr)
345345
p++;
346346
continue;
347347
}
348+
/* Sanity check to prevent dereferencing unaligned half-words */
349+
if ((((unsigned long)p) & 0x01) != 0) {
350+
p++;
351+
continue;
352+
}
348353
len = p[2] | (p[3] << 8);
349354
if ((p[0] | (p[1] << 8)) == type) {
350355
*ptr = (p + 4);
@@ -368,7 +373,8 @@ uint32_t wolfBoot_get_blob_version(uint8_t *blob)
368373
magic = (uint32_t *)blob;
369374
if (*magic != WOLFBOOT_MAGIC)
370375
return 0;
371-
wolfBoot_find_header(blob + IMAGE_HEADER_OFFSET, HDR_VERSION, (void *)&version_field);
376+
if (wolfBoot_find_header(blob + IMAGE_HEADER_OFFSET, HDR_VERSION, (void *)&version_field) == 0)
377+
return 0;
372378
if (version_field)
373379
return *version_field;
374380
return 0;
@@ -434,7 +440,8 @@ uint16_t wolfBoot_get_image_type(uint8_t part)
434440
magic = (uint32_t *)image;
435441
if (*magic != WOLFBOOT_MAGIC)
436442
return 0;
437-
wolfBoot_find_header(image + IMAGE_HEADER_OFFSET, HDR_IMG_TYPE, (void *)&type_field);
443+
if (wolfBoot_find_header(image + IMAGE_HEADER_OFFSET, HDR_IMG_TYPE, (void *)&type_field) == 0)
444+
return 0;
438445
if (type_field)
439446
return *type_field;
440447
}

0 commit comments

Comments
 (0)