From nobody@FreeBSD.ORG Fri Nov 19 16:16:08 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id C165215127; Fri, 19 Nov 1999 16:16:07 -0800 (PST)
Message-Id: <19991120001607.C165215127@hub.freebsd.org>
Date: Fri, 19 Nov 1999 16:16:07 -0800 (PST)
From: cynbe@muq.org
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: coredump in sprintf with long long args
X-Send-Pr-Version: www-1.0

>Number:         15002
>Category:       misc
>Synopsis:       coredump in sprintf with long long args
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 19 16:20:00 PST 1999
>Closed-Date:    Sat Nov 20 05:13:42 PST 1999
>Last-Modified:  Sat Nov 20 05:14:44 PST 1999
>Originator:     Cynbe ru Taren
>Release:        FreeBSD 2.2.7-RELEASE g  on intel.
>Organization:
muq.org
>Environment:
(I do not have access to the machine in question.)
>Description:
A user reported Muq (a program I maintain) coredumps on his freebsd
box.  Reproduced the problem using the following simple test program.
(I.e., emailed it to him and he reports that it dumps core also.)
I am unable to localize the problem further.
>How-To-Repeat:
/* 99Nov19CrT Test program for Muq problem */
/* on     FreeBSD 2.2.7-RELEASE g          */
/* using  gcc 2.7.2.1 Intel,               */
/* reported by Laurent Bossavit morendil@mmanian.com */
/*                                         */
/* Compile and test just by doing          */
/*                                         */
/* gcc x.c -o x                            */
/* ./x                                     */
#include <stdio.h>
int
main(
    int    argc,
    char** argv
) {
    long long sys_Ip0      = (long long) 205;
    long long sys_Ip1      = (long long) 178;
    long long sys_Ip2      = (long long) 16;
    long long sys_Ip3      = (long long) 44;
    long long sys_Muq_Port = (long long) 30023;
    unsigned char jobbuf[32];
    unsigned char nambuf[32];
    unsigned char datbuf[32];
    unsigned char buffer[8192*2];
    strcpy( datbuf, "1999/11/19/13:15:22.984" );
    strcpy( jobbuf, ""                        );
    strcpy( nambuf, ""                        );
    /* Write log line prefix: */
    sprintf(
        buffer,
        "date:%s muq:%03lld.%03lld.%03lld.%03lld:%05lld job:%16s user:%-16s msg: ",
        datbuf,
        sys_Ip0,
        sys_Ip1,
        sys_Ip2,
        sys_Ip3,
        sys_Muq_Port,
        jobbuf,
        nambuf
    );
    printf("buffer = '%s'\n", buffer );
    exit(0);
}

>Fix:
Given code works fine on linux:  If FreeBSD is switching to
glibc, that will presumably resolve the problem.

>Release-Note:
>Audit-Trail:

From: Thomas David Rivers <rivers@dignus.com>
To: cynbe@muq.org, freebsd-gnats-submit@FreeBSD.ORG
Cc:  
Subject: Re: misc/15002: coredump in sprintf with long long args
Date: Fri, 19 Nov 1999 19:31:12 -0500 (EST)

 I get the following from your program using FreeBSD 3.3-RELEASE:
 
    buffer = 'date:1999/11/19/13:15:22.984 muq:205.178.016.044:30023 job:                 user:                 msg: '
 
 
 So I believe whatever problem you are having may already
 been fixed.
 
 You may want to upgrade to a more recent release (2.2.7 is a little
 dated.)
 
 	- Dave Rivers -
 
 
State-Changed-From-To: open->closed 
State-Changed-By: billf 
State-Changed-When: Fri Nov 19 17:46:55 PST 1999 
State-Changed-Why:  
Thomas David Rivers <rivers@dignus.com> reports that this works in 
later versions of FreeBSD. 2.2.7 is rather outdated. 

The submitter must be on some fine crack to think we're switching 
to glibc. 
State-Changed-From-To: closed->analyzed 
State-Changed-By: bde 
State-Changed-When: Sat Nov 20 05:09:21 PST 1999 
State-Changed-Why:  
To actually explain the problem. 

The problem is a printf format error.  The nonstandard format "%lld" was 
not supported in FreeBSD until FreeBSD-3.2.  The 4.4BSD format "%qd" must 
be used to print long longs (at least on i386's) under earler versions. 
State-Changed-From-To: analyzed->closed 
State-Changed-By: bde 
State-Changed-When: Sat Nov 20 05:13:42 PST 1999 
State-Changed-Why:  
Now it's really closed. 
>Unformatted:
