lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1172707951.11911.3.camel@johannes.berg>
Date:	Thu, 01 Mar 2007 01:12:31 +0100
From:	Johannes Berg <johannes@...solutions.net>
To:	Linux Kernel list <linux-kernel@...r.kernel.org>
Subject: [PATCH] make sscanf honor %n 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);

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. This
patch changes that.

Signed-off-by: Johannes Berg <johannes@...solutions.net>

---
Shrug. My use case for this collapsed, but I figured having scanf doing
that correctly might be a good thing.

 lib/vsprintf.c |    9 +++++++++
 1 file changed, 9 insertions(+)

--- wireless-dev.orig/lib/vsprintf.c	2007-03-01 00:28:31.776381760 +0100
+++ wireless-dev/lib/vsprintf.c	2007-03-01 00:59:33.256381760 +0100
@@ -825,6 +825,15 @@ int vsscanf(const char * buf, const char
 			break;
 		str = next;
 	}
+
+	/* Now we've come all the way through so either the input string or
+	 * the format ended. In the former case, there can be a %n at the
+	 * current position in the format that needs to be filled. */
+	if (*fmt == '%' && *(fmt+1) == 'n') {
+		int *i = (int *)va_arg(args,int*);
+		*i = str - buf;
+	}
+
 	return num;
 }
 


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ