From 430900ea2ca6ad0eba6c169ed80b63ff1dfde36e Mon Sep 17 00:00:00 2001 From: mcudev <29890609+mcudev@users.noreply.github.com> Date: Mon, 6 Nov 2017 06:47:42 -0500 Subject: [PATCH] boardloader: ensure check_sdcard fails when read fails --- embed/boardloader/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/embed/boardloader/main.c b/embed/boardloader/main.c index ebe691ece2..25f36ac5eb 100644 --- a/embed/boardloader/main.c +++ b/embed/boardloader/main.c @@ -40,13 +40,15 @@ static uint32_t check_sdcard(void) uint32_t buf[IMAGE_HEADER_SIZE / sizeof(uint32_t)]; - sdcard_read_blocks(buf, 0, IMAGE_HEADER_SIZE / SDCARD_BLOCK_SIZE); + memset(buf, 0, sizeof(buf)); + + const secbool read_status = sdcard_read_blocks(buf, 0, IMAGE_HEADER_SIZE / SDCARD_BLOCK_SIZE); sdcard_power_off(); image_header hdr; - if (sectrue == load_image_header((const uint8_t *)buf, BOOTLOADER_IMAGE_MAGIC, BOOTLOADER_IMAGE_MAXSIZE, BOARDLOADER_KEY_M, BOARDLOADER_KEY_N, BOARDLOADER_KEYS, &hdr)) { + if ((sectrue == read_status) && (sectrue == load_image_header((const uint8_t *)buf, BOOTLOADER_IMAGE_MAGIC, BOOTLOADER_IMAGE_MAXSIZE, BOARDLOADER_KEY_M, BOARDLOADER_KEY_N, BOARDLOADER_KEYS, &hdr))) { return hdr.codelen; } else { return 0;