From nobody@FreeBSD.org  Fri Aug  9 00:23:45 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 809897AF
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Aug 2013 00:23:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 6DE402E16
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Aug 2013 00:23:45 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r790Nj1I011597
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 9 Aug 2013 00:23:45 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r790Njuu011594;
	Fri, 9 Aug 2013 00:23:45 GMT
	(envelope-from nobody)
Message-Id: <201308090023.r790Njuu011594@oldred.freebsd.org>
Date: Fri, 9 Aug 2013 00:23:45 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sscanf doesn't skip whitespace properly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181153
>Category:       kern
>Synopsis:       sscanf(3) doesn't skip whitespace properly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 09 00:30:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Fri Aug  9 02:20:00 UTC 2013
>Originator:     Garrett Cooper
>Release:        10-CURRENT
>Organization:
EMC Isilon
>Environment:
FreeBSD fuji-current.local 10.0-CURRENT FreeBSD 10.0-CURRENT #10 c9d2bd6-dirty: Wed Aug  7 18:55:03 PDT 2013     root@fuji-current.local:/usr/obj/usr/src/sys/FUJI-NOCOMPAT  i386
>Description:
The following test failure occurred:

    sscanf_whitespace: [0.001968s] Failed: /usr/src/lib/libc/tests/stdio/t_scanf.c:71: c == 'z' not met

The corresponding test code of interest is as follows:

ATF_TC(sscanf_whitespace);
ATF_TC_HEAD(sscanf_whitespace, tc)
{

        atf_tc_set_md_var(tc, "descr", "verify sscanf skips all whitespace");
}

ATF_TC_BODY(sscanf_whitespace, tc)
{
        const char str[] = "\f\n\r\t\v%z";
        char c;

        /* set of "white space" symbols from isspace(3) */
        c = 0;
        (void)sscanf(str, "%%%c", &c);
        ATF_REQUIRE(c == 'z');
}
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Andrey Chernov <ache@freebsd.org>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/181153: sscanf doesn't skip whitespace properly
Date: Fri, 09 Aug 2013 05:24:20 +0400

 On 09.08.2013 4:23, Garrett Cooper wrote:
 > ATF_TC_BODY(sscanf_whitespace, tc)
 > {
 >         const char str[] = "\f\n\r\t\v%z";
 >         char c;
 > 
 >         /* set of "white space" symbols from isspace(3) */
 >         c = 0;
 >         (void)sscanf(str, "%%%c", &c);
 >         ATF_REQUIRE(c == 'z');
 > }
 
 I doubt this exampe should skip whitespace. POSIX says:
 "A directive that is an ordinary character shall be executed as follows:
 the next byte shall be read from the input and compared with the byte
 that comprises the directive; if the comparison shows that they are not
 equivalent, the directive shall fail, and the differing and subsequent
 bytes shall remain unread."
 %% is the ordinary % character and no isspace(3) skipping mentioned in
 this explanation.
 
 -- 
 http://ache.vniz.net/
 bitcoin:1G6ugdNY6e5jx1GVnAU2ntj2NEfmjKG85r

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Andrey Chernov <ache@freebsd.org>
Cc: "FreeBSD-gnats-submit@FreeBSD.org" <freebsd-gnats-submit@freebsd.org>
Subject: Re: bin/181153: sscanf doesn't skip whitespace properly
Date: Thu, 8 Aug 2013 19:03:10 -0700

 On Thu, Aug 8, 2013 at 6:24 PM, Andrey Chernov <ache@freebsd.org> wrote:
 > On 09.08.2013 4:23, Garrett Cooper wrote:
 >> ATF_TC_BODY(sscanf_whitespace, tc)
 >> {
 >>         const char str[] = "\f\n\r\t\v%z";
 >>         char c;
 >>
 >>         /* set of "white space" symbols from isspace(3) */
 >>         c = 0;
 >>         (void)sscanf(str, "%%%c", &c);
 >>         ATF_REQUIRE(c == 'z');
 >> }
 >
 > I doubt this exampe should skip whitespace. POSIX says:
 > "A directive that is an ordinary character shall be executed as follows:
 > the next byte shall be read from the input and compared with the byte
 > that comprises the directive; if the comparison shows that they are not
 > equivalent, the directive shall fail, and the differing and subsequent
 > bytes shall remain unread."
 > %% is the ordinary % character and no isspace(3) skipping mentioned in
 > this explanation.
 
 What about this line [*]?
 
 "
 A directive composed of one or more white-space characters is executed
 by reading input until no more valid input can be read, or up to the
 first byte which is not a white-space character which remains unread.
 "
 
 I think this is what the NetBSD test developer was shooting for originally.
 
 FWIW I did print out the value previously and it was (char)0, or '\0'.
 
 Thanks!
 
 * http://pubs.opengroup.org/onlinepubs/7908799/xsh/fscanf.html

From: Andrey Chernov <ache@freebsd.org>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: "FreeBSD-gnats-submit@FreeBSD.org" <freebsd-gnats-submit@freebsd.org>
Subject: Re: bin/181153: sscanf doesn't skip whitespace properly
Date: Fri, 09 Aug 2013 06:15:55 +0400

 On 09.08.2013 6:03, Garrett Cooper wrote:
 >> I doubt this exampe should skip whitespace. POSIX says:
 >> "A directive that is an ordinary character shall be executed as follows:
 >> the next byte shall be read from the input and compared with the byte
 >> that comprises the directive; if the comparison shows that they are not
 >> equivalent, the directive shall fail, and the differing and subsequent
 >> bytes shall remain unread."
 >> %% is the ordinary % character and no isspace(3) skipping mentioned in
 >> this explanation.
 > 
 > What about this line [*]?
 > 
 > "
 > A directive composed of one or more white-space characters is executed
 > by reading input until no more valid input can be read, or up to the
 > first byte which is not a white-space character which remains unread.
 > "
 > 
 > I think this is what the NetBSD test developer was shooting for originally.
 > 
 > FWIW I did print out the value previously and it was (char)0, or '\0'.
 > 
 > Thanks!
 > 
 > * http://pubs.opengroup.org/onlinepubs/7908799/xsh/fscanf.html
 > 
 
 I see another line here:
 http://pubs.opengroup.org/onlinepubs/9699919799/functions/sscanf.html
 (2013 Edition)
 
 "A directive that is a conversion specification defines a set of
 matching input sequences, as described below for each conversion
 character. A conversion specification shall be executed in the following
 steps.
 Input white-space characters (as specified by isspace) shall be skipped,
 unless the conversion specification includes a [, c, C, or n conversion
 specifier."
 
 Which is clearly not our case because %% is not a conversion, just
 ordinary character. And don't see there line your mentioned.
 Probably there still are skipping bugs with other %-modifiers, I don't
 inspect it carefully, but not with %%.
 
 -- 
 http://ache.vniz.net/
 bitcoin:1G6ugdNY6e5jx1GVnAU2ntj2NEfmjKG85r
>Unformatted:
