bootutil: Fix boot_write_trailer write alignment
The commit fixes alignment issue in boot_write_trailer, that would
occur in case when input buffer length would be greater than
alignment parameter of flash.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/bootutil/src/bootutil_public.c b/boot/bootutil/src/bootutil_public.c
index 7330fc9..793c4e3 100644
--- a/boot/bootutil/src/bootutil_public.c
+++ b/boot/bootutil/src/bootutil_public.c
@@ -344,13 +344,12 @@
int rc;
align = flash_area_align(fap);
- if (inlen > BOOT_MAX_ALIGN || align > BOOT_MAX_ALIGN) {
+ align = (inlen + align - 1) & ~(align - 1);
+ if (align > BOOT_MAX_ALIGN) {
return -1;
}
erased_val = flash_area_erased_val(fap);
- if (align < inlen) {
- align = inlen;
- }
+
memcpy(buf, inbuf, inlen);
memset(&buf[inlen], erased_val, align - inlen);