Commit 006994b7 authored by Fabio Utzig's avatar Fabio Utzig Committed by David Brown
Browse files

Fix a buffer overflow on EC point load

While loading a new EC point, when it was smaller than the expected
number of bytes, a zero padding was being written beyond the end of the
buffer instead of at the initial position.

While this has been working before, it broke when images were signed using
the ring API.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 90abedc7
Loading
Loading
Loading
Loading
+2 −2
Changes for boot/bootutil/src/image_ec256.c: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -99,10 +99,10 @@ tinycrypt_read_bigint(uint8_t i[NUM_ECC_BYTES], uint8_t **cp, uint8_t *end)
        return -3;
    }

    if (len > NUM_ECC_BYTES) {
    if (len >= NUM_ECC_BYTES) {
        memcpy(i, *cp + len - NUM_ECC_BYTES, NUM_ECC_BYTES);
    } else {
        memset(i + NUM_ECC_BYTES, 0, NUM_ECC_BYTES - len);
        memset(i, 0, NUM_ECC_BYTES - len);
        memcpy(i + NUM_ECC_BYTES - len, *cp, len);
    }
    *cp += len;