[PATCH] vsscanf() in lib/vsprintf.c
From: Stefan Kanthak
Date: Tue May 04 2021 - 15:30:45 EST
Hi @ll,
both <https://www.kernel.org/doc/htmldocs/kernel-api/API-sscanf.html>
and <https://www.kernel.org/doc/htmldocs/kernel-api/API-vsscanf.html>
are rather terse and fail to specify the supported arguments and their
conversion specifiers/modifiers.
<https://www.kernel.org/doc/htmldocs/kernel-api/libc.html#id-1.4.3>
tells OTOH:
| The behaviour of these functions may vary slightly from those
| defined by ANSI, and these deviations are noted in the text.
There is but no text (see above) despite multiple deviations from
ANSI C
<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/lib/vsprintf.c?h=v5.12>
| /* '%*[' not yet supported, invalid format */
...
| /*
| * Warning: This implementation of the '[' conversion specifier
| * deviates from its glibc counterpart in the following ways:
...
More deviations (just from reading the source):
1. no support for %p
2. no support for conversion modifiers j and t
3. no support for multibyte characters and strings, i.e. %<width>c
and %<width>s may split UTF-8 codepoints
4. accepts %[<width>]<modifier>[c|s], but ignores all conversion
modifiers
5. treats %<width><modifier>% (and combinations) as %%
6. accepts %<width><modifier>n (and combinations)
7. doesn't scan the input for %[...]n
8. uses simple_strto[u]l for the conversion modifier z, i.e. assigns
uint32_t to size_t, resulting in truncation
Is this intended?
If not: patch to fix 5. and 6. and simplify the qualifier handling
attached
Stefan KanthakAttachment:
vsprintf.patch
Description: Binary data