From: Andy Spencer Date: Thu, 1 Oct 2009 22:44:27 +0000 (-0700) Subject: sscanf(): fix %*s%n X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8fccae2c95506270f74ee8429c273b0924e89c83;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git sscanf(): fix %*s%n 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. Signed-off-by: Andy Spencer Acked-by: WANG Cong Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index b91839e9e892..33bed5e67a21 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1771,7 +1771,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++;