Skip to content

Commit 542ea03

Browse files
tpambordanieldegrasse
authored andcommitted
include: cbprintf: Fix call to memcpy with null pointer
cbprintf_package_convert may invoke z_cbprintf_cpy with a null pointer to buf and zero length to indicate a flush operation. This triggers an error from the undefined behavior sanitizer due to memcpy being called with a null src, which is undefined behavior according to the C standard. This is avoided by exiting early in z_cbprintf_cpy when length is zero. Signed-off-by: Tim Pambor <[email protected]>
1 parent 44aaa84 commit 542ea03

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/zephyr/sys/cbprintf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ static inline int z_cbprintf_cpy(const void *buf, size_t len, void *ctx)
529529
{
530530
struct z_cbprintf_buf_desc *desc = (struct z_cbprintf_buf_desc *)ctx;
531531

532+
if (len == 0) {
533+
return 0;
534+
}
535+
532536
if ((desc->size - desc->off) < len) {
533537
return -ENOSPC;
534538
}

0 commit comments

Comments
 (0)