diff --git a/include/sys/cbprintf.h b/include/sys/cbprintf.h index f4b3f56378f..51700bca37a 100644 --- a/include/sys/cbprintf.h +++ b/include/sys/cbprintf.h @@ -139,6 +139,7 @@ typedef int (*cbprintf_cb)(/* int c, void *ctx */); * @retval nonegative the number of bytes successfully stored at @p packaged. * This will not exceed @p len. * @retval -EINVAL if @p format is not acceptable + * @retval -EFAULT if @p packaged alignment is not acceptable * @retval -ENOSPC if @p packaged was not null and the space required to store * exceed @p len. */ diff --git a/lib/os/cbprintf_packaged.c b/lib/os/cbprintf_packaged.c index 68a9aec0ca6..24e50d2f512 100644 --- a/lib/os/cbprintf_packaged.c +++ b/lib/os/cbprintf_packaged.c @@ -374,6 +374,11 @@ int cbvprintf_package(void *packaged, size_t len, /* align destination buffer location */ buf = (void *) ROUND_UP(buf, align); + /* Check if buffer is properly aligned. */ + if ((uintptr_t)buf0 & (align - 1)) { + return -EFAULT; + } + /* make sure the data fits */ if (buf0 && buf - buf0 + size > len) { return -ENOSPC;