From owner-freebsd-audit Sat Jun 23 5:14:55 2001 Delivered-To: freebsd-audit@freebsd.org Received: from ringworld.nanolink.com (ringworld.nanolink.com [195.24.48.13]) by hub.freebsd.org (Postfix) with SMTP id DDD4137B408 for ; Sat, 23 Jun 2001 05:14:48 -0700 (PDT) (envelope-from roam@ringworld.nanolink.com) Received: (qmail 616 invoked by uid 1000); 23 Jun 2001 12:13:10 -0000 Date: Sat, 23 Jun 2001 15:13:10 +0300 From: Peter Pentchev To: arch@FreeBSD.org Cc: audit@FreeBSD.org Subject: patch for '%lld' handling in *scanf(3) Message-ID: <20010623151310.A497@ringworld.oblivion.bg> Mail-Followup-To: arch@FreeBSD.org, audit@FreeBSD.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, scanf(3) does not understand %lld for 'long long', it only understands %qd, and it treats %lld as plain %ld. printf(3) prints out %lld just fine. The fix needed is just three lines of code, which have been in both NetBSD and OpenBSD for some time. Demonstration: the following program: #include #include int main(void) { quad_t x = 0xeFFFFFFFFFFFFFFe; scanf("%lld", &x); printf("%llx\n", x); return (0); } Before: [roam@freefall ~/c/misc/foo]$ ./foo7 5 efffffff00000005 [roam@freefall ~/c/misc/foo]$ After: [roam@ringworld:v4 ~/c/misc/foo]$ ./foo7 5 5 [roam@ringworld:v4 ~/c/misc/foo]$ The patch is attached. OK, so maybe this patch is not quite semantically correct; it tends to assume that 'long long' is the same as 'quad', or at least, that the programmer asked for 'quad' by using %lld. A 'real' fix would be defining a LONGLONG flag for scanf(). G'luck, Peter -- When you are not looking at it, this sentence is in Spanish. Index: src/lib/libc/stdio/vfscanf.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdio/vfscanf.c,v retrieving revision 1.16 diff -u -r1.16 vfscanf.c --- src/lib/libc/stdio/vfscanf.c 2001/02/10 05:46:05 1.16 +++ src/lib/libc/stdio/vfscanf.c 2001/06/23 12:12:30 @@ -186,7 +186,12 @@ flags |= SUPPRESS; goto again; case 'l': - flags |= LONG; + if (*fmt == 'l') { + fmt++; + flags |= QUAD; + } else { + flags |= LONG; + } goto again; case 'q': flags |= QUAD; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message