diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2007-05-08 03:27:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:15:05 -0400 |
commit | c6b40d16d1cfa1a01158049bb887a9bbe48ef7ba (patch) | |
tree | 72eac6e26f928780fe722ad45ff6eeb6807d2356 /lib/vsprintf.c | |
parent | 757dea93e136b219af09d3cd56a81063fdbdef1a (diff) |
fix sscanf %n match at end of input string
I was playing with some code that sometimes got a string where a %n
match should have been done where the input string ended, for example
like this:
sscanf("abc123", "abc%d%n", &a, &n); /* doesn't work */
sscanf("abc123a", "abc%d%n", &a, &n); /* works */
However, the scanf function in the kernel doesn't convert the %n in that
case because it has already matched the complete input after %d and just
completely stops matching then. This patch fixes that.
[akpm@linux-foundation.org: cleanups]
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index cbab1df150cf..017290241261 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -825,6 +825,17 @@ int vsscanf(const char * buf, const char * fmt, va_list args) | |||
825 | break; | 825 | break; |
826 | str = next; | 826 | str = next; |
827 | } | 827 | } |
828 | |||
829 | /* | ||
830 | * Now we've come all the way through so either the input string or the | ||
831 | * format ended. In the former case, there can be a %n at the current | ||
832 | * position in the format that needs to be filled. | ||
833 | */ | ||
834 | if (*fmt == '%' && *(fmt + 1) == 'n') { | ||
835 | int *p = (int *)va_arg(args, int *); | ||
836 | *p = str - buf; | ||
837 | } | ||
838 | |||
828 | return num; | 839 | return num; |
829 | } | 840 | } |
830 | 841 | ||