Re: [PATCH] fix %*s%n in sscanf

From: AmÃrico Wang
Date: Fri Sep 25 2009 - 03:02:44 EST


On Fri, Sep 25, 2009 at 2:27 PM, Andy Spencer <andy753421@xxxxxxxxx> 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@xxxxxxxxx>


Fortunately, a quick grep shows no one uses '%*' in sscanf()
in kernel space:

% grep 'sscanf(.*\".*%\*.*\".*)' -nr ./

For completeness,

Acked-by: WANG Cong <xiyou.wangcong@xxxxxxxxx>

>
> 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++;
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/