* [PATCH] fix %*s%n in sscanf
@ 2009-09-25 6:27 Andy Spencer
2009-09-25 7:02 ` Américo Wang
0 siblings, 1 reply; 3+ messages in thread
From: Andy Spencer @ 2009-09-25 6:27 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 949 bytes --]
When using %*s, sscanf should honor conversion specifiers immediately following
the %*s. For example, the following code should find the position of the end of
the string "hello".
int end;
char buf[] = "hello world";
sscanf(buf, "%*s%n", &end);
printf("%d\n", end);
Ideally, sscanf would advance the fmt and str pointers the same as it would
without the *, but the code for that is rather complicated and is not included
in the patch.
Please CC me in replies.
Signed-off-by: Andy Spencer <andy753421@gmail.com>
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 73a14b8..da2daf2 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1766,7 +1766,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
* advance both strings to next white space
*/
if (*fmt == '*') {
- while (!isspace(*fmt) && *fmt)
+ while (!isspace(*fmt) && *fmt != '%' && *fmt)
fmt++;
while (!isspace(*str) && *str)
str++;
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] fix %*s%n in sscanf
2009-09-25 6:27 [PATCH] fix %*s%n in sscanf Andy Spencer
@ 2009-09-25 7:02 ` Américo Wang
2009-09-25 10:42 ` Andy Spencer
0 siblings, 1 reply; 3+ messages in thread
From: Américo Wang @ 2009-09-25 7:02 UTC (permalink / raw)
To: Andy Spencer; +Cc: linux-kernel
On Fri, Sep 25, 2009 at 2:27 PM, Andy Spencer <andy753421@gmail.com> wrote:
> When using %*s, sscanf should honor conversion specifiers immediately following
> the %*s. For example, the following code should find the position of the end of
> the string "hello".
>
> int end;
> char buf[] = "hello world";
> sscanf(buf, "%*s%n", &end);
> printf("%d\n", end);
>
> Ideally, sscanf would advance the fmt and str pointers the same as it would
> without the *, but the code for that is rather complicated and is not included
> in the patch.
Yeah, seems reasonable. So, without your patch, sscanf() in kernel
will ignore everything after '*', right?
>
> Please CC me in replies.
>
>
> Signed-off-by: Andy Spencer <andy753421@gmail.com>
Fortunately, a quick grep shows no one uses '%*' in sscanf()
in kernel space:
% grep 'sscanf(.*\".*%\*.*\".*)' -nr ./
For completeness,
Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 73a14b8..da2daf2 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1766,7 +1766,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
> * advance both strings to next white space
> */
> if (*fmt == '*') {
> - while (!isspace(*fmt) && *fmt)
> + while (!isspace(*fmt) && *fmt != '%' && *fmt)
> fmt++;
> while (!isspace(*str) && *str)
> str++;
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] fix %*s%n in sscanf
2009-09-25 7:02 ` Américo Wang
@ 2009-09-25 10:42 ` Andy Spencer
0 siblings, 0 replies; 3+ messages in thread
From: Andy Spencer @ 2009-09-25 10:42 UTC (permalink / raw)
To: Am??rico Wang; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 382 bytes --]
> > int end;
> > char buf[] = "hello world";
> > sscanf(buf, "%*s%n", &end);
> > printf("%d\n", end);
>
> Yeah, seems reasonable. So, without your patch, sscanf() in kernel
> will ignore everything after '*', right?
Currently it ignores everything between '*' and whitespace. So '%*s%n'
does not work, but '%*s %n' will correctly return the start of "world".
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-25 10:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-25 6:27 [PATCH] fix %*s%n in sscanf Andy Spencer
2009-09-25 7:02 ` Américo Wang
2009-09-25 10:42 ` Andy Spencer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®