Bug 15002

Summary: coredump in sprintf with long long args
Product: Base System Reporter: cynbe <cynbe>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 2.2.7-RELEASE   
Hardware: Any   
OS: Any   

Description cynbe 1999-11-20 00:20:00 UTC
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.

Fix: 

Given code works fine on linux:  If FreeBSD is switching to
glibc, that will presumably resolve the problem.
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);
}
Comment 1 Thomas David Rivers 1999-11-20 00:31:12 UTC
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 -
Comment 2 bill fumerola freebsd_committer freebsd_triage 1999-11-20 01:46:55 UTC
State Changed
From-To: open->closed

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. 
Comment 3 Bruce Evans freebsd_committer freebsd_triage 1999-11-20 13:09:21 UTC
State Changed
From-To: closed->analyzed

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. 
Comment 4 Bruce Evans freebsd_committer freebsd_triage 1999-11-20 13:13:42 UTC
State Changed
From-To: analyzed->closed

Now it's really closed.