Skip to content

Commit

Permalink
lib: cbprintf: do not blindly skip tags
Browse files Browse the repository at this point in the history
When CONFIG_LOG_USE_TAGGED_ARGUMENTS is enabled, and
CONFIG_CBPRINTF_COMPLETE is also enabled, we should not be
blindly skipping tags when processing the tagged package
for output.  The issue is that if there is a "%%" in
the format string, the specifier is considered invalid but
the code blindly skips ahead in the argument list as if
it is a valid specifier (think "%s"), which resulting in
the next valid specifier using incorrect argument in
the list. So fix it by skipping ahead if and only if
the specifier is not invalid.

Fixes #68271

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
dcpleung authored and henrikbrixandersen committed Feb 6, 2024
1 parent 7812e54 commit 627d3b2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/os/cbprintf_complete.c
Original file line number Diff line number Diff line change
@@ -1378,14 +1378,6 @@ int z_cbvprintf_impl(cbprintf_cb out, void *ctx, const char *fp,
continue;
}

if (IS_ENABLED(CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS)
&& tagged_ap) {
/* Skip over the argument tag as it is not being
* used here.
*/
(void)va_arg(ap, int);
}

/* Force union into RAM with conversion state to
* mitigate LLVM code generation bug.
*/
@@ -1408,6 +1400,16 @@ int z_cbvprintf_impl(cbprintf_cb out, void *ctx, const char *fp,

fp = extract_conversion(conv, sp);

if (conv->specifier_cat != SPECIFIER_INVALID) {
if (IS_ENABLED(CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS)
&& tagged_ap) {
/* Skip over the argument tag as it is not being
* used here.
*/
(void)va_arg(ap, int);
}
}

/* If dynamic width is specified, process it,
* otherwise set width if present.
*/

0 comments on commit 627d3b2

Please sign in to comment.