NetBSD Problem Report #48517

From www@NetBSD.org  Mon Jan 13 11:47:06 2014
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id ED1E6A61B7
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 13 Jan 2014 11:47:05 +0000 (UTC)
Message-Id: <20140113114704.AD068A646D@mollari.NetBSD.org>
Date: Mon, 13 Jan 2014 11:47:04 +0000 (UTC)
From: m4j0rd0m0@gmail.com
Reply-To: m4j0rd0m0@gmail.com
To: gnats-bugs@NetBSD.org
Subject: snprintb(3) adds extra '>' to string-converted value when nothing matches
X-Send-Pr-Version: www-1.0

>Number:         48517
>Category:       lib
>Synopsis:       snprintb(3) adds extra '>' to string-converted value when nothing matches
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 13 11:50:00 +0000 2014
>Closed-Date:    Fri Jun 06 07:16:34 +0000 2014
>Last-Modified:  Sat Aug 02 11:20:00 +0000 2014
>Originator:     Felix Deichmann
>Release:        current and 6.1.2
>Organization:
>Environment:
- NetBSD 6.99.28 (GENERIC) amd64 build of 201401121400Z (nyftp.netbsd.org)
- NetBSD 6.1.2 (GENERIC) amd64
>Description:
When snprintb(3) has no match (e. g. converts a value of 0), it adds an extra '>' to the value in the converted string, e. g. "0x0>".
See the following code example.

I would expect it to just convert to "0x0" then.
>How-To-Repeat:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <util.h>

/* -------------------------------------------------------------------------- */

int
main(void)
{
        char strbuf[80];

        (void)snprintb(strbuf, sizeof(strbuf) / sizeof(strbuf[0]),
                       "\177\20"        /* new format, base 16 */
                       "b\0A\0"         /* bit 0 = A */
                       "\0",
                       0);
        printf("%s\n", strbuf); /* prints "0x0>\n"... */

        return (strcmp("0x0", strbuf) == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

>Fix:

>Release-Note:

>Audit-Trail:
From: "Mateusz Kocielski" <shm@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48517 CVS commit: src/tests/lib/libutil
Date: Fri, 6 Jun 2014 06:59:21 +0000

 Module Name:	src
 Committed By:	shm
 Date:		Fri Jun  6 06:59:21 UTC 2014

 Modified Files:
 	src/tests/lib/libutil: t_snprintb.c

 Log Message:
 PR/48517 testcase provided by Felix Deichmann


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libutil/t_snprintb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Mateusz Kocielski" <shm@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48517 CVS commit: src/common/lib/libutil
Date: Fri, 6 Jun 2014 07:08:37 +0000

 Module Name:	src
 Committed By:	shm
 Date:		Fri Jun  6 07:08:37 UTC 2014

 Modified Files:
 	src/common/lib/libutil: snprintb.c

 Log Message:
 PR/48517 do not add extra '>' to string-converted value when nothing matches


 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.15 src/common/lib/libutil/snprintb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: shm@NetBSD.org
State-Changed-When: Fri, 06 Jun 2014 07:16:34 +0000
State-Changed-Why:
the bug stops here


From: Ryo Shimizu <ryo@nerv.org>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, netbsd-bugs@netbsd.org,
    gnats-admin@netbsd.org, shm@NetBSD.org, m4j0rd0m0@gmail.com
Subject: Re: lib/48517 (snprintb(3) adds extra '>' to string-converted value when nothing matches)
Date: Fri, 01 Aug 2014 18:10:45 +0900

 >Synopsis: snprintb(3) adds extra '>' to string-converted value when nothing matches
 >
 >State-Changed-From-To: open->closed
 >State-Changed-By: shm@NetBSD.org
 >State-Changed-When: Fri, 06 Jun 2014 07:16:34 +0000
 >State-Changed-Why:
 >the bug stops here

 there is bugs yet in below case.

 % cat x.c
 #include <stdio.h>
 #include <util.h>

 int
 main(int argc, char *argv[])
 {
 	char tmp[1024];

 	/* no match any bit, and value not zero */
 	snprintb(tmp, sizeof(tmp), "\20\01ONE\02TWO\03TREE", 8);
 	printf("%s\n", tmp);	/* result "0x8>" */

 	snprintb(tmp, sizeof(tmp), "\177\020b\x1f" "MSB\0", 1);
 	printf("%s\n", tmp);	/* result "0x1>" */

 	/* value is zero in new format */
 	snprintb(tmp, sizeof(tmp),
 		"\177\020"
 		"f\x10" "\4" "BURST\0"
 		"=\0" "ZERO\0"
 		"=\4" "FOUR\0"
 		"=\xf" "SIXTEEN\0",
 		0);
 	printf("%s\n", tmp);	/* result "0x0<BURST=0x0=ZERO" */

 	return 0;
 }

 % cc -Wall x.c -lutil
 % ./a.out 
 0x8>
 0x1>
 0x0<BURST=0x0=ZERO

 >Fix:
 cvs -q diff -aup
 Index: snprintb.c
 ===================================================================
 RCS file: /cvsroot/src/common/lib/libutil/snprintb.c,v
 retrieving revision 1.15
 diff -a -u -p -r1.15 snprintb.c
 --- snprintb.c	6 Jun 2014 07:08:37 -0000	1.15
 +++ snprintb.c	1 Aug 2014 08:41:03 -0000
 @@ -257,7 +257,7 @@ snprintb_m(char *buf, size_t buflen, con
  		}
  	}
  	l_len++;
 -	if (val != 0 && (size_t)(++t_len) < buflen)
 +	if (sep != '<' && (size_t)(++t_len) < buflen)
  		*bp++ = '>';
  terminate:
  	*bp++ = '\0';


 % cc -Wall x.c -lutil
 % ./a.out 
 0x8
 0x1
 0x0<BURST=0x0=ZERO>


 --
 ryo shimizu

From: "Ryo Shimizu" <ryo@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48517 CVS commit: src/common/lib/libutil
Date: Sat, 2 Aug 2014 11:19:01 +0000

 Module Name:	src
 Committed By:	ryo
 Date:		Sat Aug  2 11:19:01 UTC 2014

 Modified Files:
 	src/common/lib/libutil: snprintb.c

 Log Message:
 fix lack of '>' pointed out in PR/48517


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.16 src/common/lib/libutil/snprintb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.