Skip to content

vsnprintfcb writes to *str if it is NULL #48394

@sw

Description

@sw

vsnprintfcb will write to the given string buffer even if the pointer is NULL:

zephyr/lib/os/cbprintf.c

Lines 105 to 109 in 3462a2a

if (ctx.dp < ctx.dpe) {
ctx.dp[0] = 0;
} else {
ctx.dp[-1] = 0;
}

Apparently having str==NULL && size==0 is valid: https://stackoverflow.com/a/37173612

The code above obviously needs to be wrapped in an if condition, but what about struct str_ctx? Adding 0 to a NULL pointer is fine AFAIK, but cbvprintf may do something naughty with that.

Metadata

Metadata

Assignees

Labels

Stalearea: Base OSBase OS Library (lib/os)bugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions