From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Stefan Kanthak <kanthak@arcor.de>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vsscanf() in lib/vsprintf.c
Date: Wed, 5 May 2021 16:35:52 +0200 [thread overview]
Message-ID: <91e60831-3f8b-a81d-1204-872b5ee79feb@rasmusvillemoes.dk> (raw)
In-Reply-To: <6C7CD73845304CDE98F6DB165904B571@H270>
On 04/05/2021 21.19, Stefan Kanthak wrote:
> 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
What on earth good would that do in the kernel?
> 2. no support for conversion modifiers j and t
Could be added, but do you have a user?
> 3. no support for multibyte characters and strings, i.e. %<width>c
> and %<width>s may split UTF-8 codepoints
So what? The kernel doesn't do a lot of text processing and wchar_t stuff.
> 4. accepts %[<width>]<modifier>[c|s], but ignores all conversion
> modifiers
Yeah, %ls is technically accepted and treated as %s, that's mostly for
ease of parsing it seems. Do you have a use case where you'd want wchar_ts?
> 5. treats %<width><modifier>% (and combinations) as %%
What would you expect it to do? Seems to be a non-issue, gcc flags that
nonsense just fine
vs.c: In function ‘v’:
vs.c:5:18: warning: conversion lacks type at end of format [-Wformat=]
5 | x = sscanf(s, "%l% %d", &y);
| ^
vs.c:5:20: warning: unknown conversion type character ‘ ’ in format
[-Wformat=]
5 | x = sscanf(s, "%l% %d", &y);
| ^
> 6. accepts %<width><modifier>n (and combinations)
Again, non-issue (warning: field width used with ‘%n’ gnu_scanf format)
> 7. doesn't scan the input for %[...]n
? What's that supposed to mean.
> 8. uses simple_strto[u]l for the conversion modifier z, i.e. assigns
> uint32_t to size_t, resulting in truncation
Where do you see uint32_t? The code is
val.u = qualifier != 'L' ?
simple_strtoul(str, &next, base) :
simple_strtoull(str, &next, base);
case 'z':
*va_arg(args, size_t *) = val.u;
break;
so the conversion is done with simple_strtoul which return "unsigned
long". And size_t is either a typedef for "unsigned long" or "unsigned
int", so yes, of course a truncation may happen, but if the value
actually fits in a size_t, it also fits in unsigned long (as returned
from simple_strtoul) and unsigned long long (as stored in val.u).
Rasmus
next prev parent reply other threads:[~2021-05-05 14:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-04 19:19 [PATCH] vsscanf() in lib/vsprintf.c Stefan Kanthak
2021-05-05 10:49 ` David Laight
2021-05-05 14:35 ` Rasmus Villemoes [this message]
2021-05-05 16:41 ` Stefan Kanthak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=91e60831-3f8b-a81d-1204-872b5ee79feb@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=kanthak@arcor.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).