lib: os: cbprintf: Add alignment check to cbprintf_package
Added validation of alignment to cbprintf_package. Error is returned if input buffer is not aligned to the largest argument. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
a92214b8f4
commit
9966d85c0a
2 changed files with 6 additions and 0 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue