NetBSD Problem Report #32097

From www@netbsd.org  Thu Nov 17 10:49:11 2005
Return-Path: <www@netbsd.org>
Received: by narn.netbsd.org (Postfix, from userid 31301)
	id C279463BA17; Thu, 17 Nov 2005 10:49:11 +0000 (UTC)
Message-Id: <20051117104911.C279463BA17@narn.netbsd.org>
Date: Thu, 17 Nov 2005 10:49:11 +0000 (UTC)
From: segv@netctl.net
Reply-To: segv@netctl.net
To: gnats-bugs@netbsd.org
Subject: pkgsrc bootstrap 'tar' command segfaults on Sparc Solaris 10
X-Send-Pr-Version: www-1.0

>Number:         32097
>Category:       pkg
>Synopsis:       pkgsrc bootstrap 'tar' command segfaults on Sparc Solaris 10
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    solaris-pkg-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 17 10:50:00 +0000 2005
>Closed-Date:    Tue Jun 27 09:01:58 +0000 2006
>Last-Modified:  Tue Jun 27 09:01:58 +0000 2006
>Originator:     segv
>Release:        
>Organization:
>Environment:
SunOS ultra10 5.10 Generic sun4u sparc SUNW,Ultra-5_10
>Description:
After bootstrapping pkgsrc utilities with Sun Studio 11 compilers on UltraSparc machine, 'tar' command dies with SEGV and dumps a core. There are no problems when bootstrapping with GCC
>How-To-Repeat:
Bootstrap pkgsrc then use /usr/pkg/bin/tar to create a .tgz file.
>Fix:

>Release-Note:

>Audit-Trail:
From: grant beattie <grant@NetBSD.org>
To: gnats-bugs@netbsd.org
Cc: pkg-manager@netbsd.org, gnats-admin@netbsd.org,
	pkgsrc-bugs@netbsd.org
Subject: Re: pkg/32097: pkgsrc bootstrap 'tar' command segfaults on Sparc Solaris 10
Date: Thu, 17 Nov 2005 23:14:06 +1100

 On Thu, Nov 17, 2005 at 10:50:00AM +0000, segv@netctl.net wrote:

 > >Number:         32097
 > >Category:       pkg
 > >Synopsis:       pkgsrc bootstrap 'tar' command segfaults on Sparc Solaris 10
 > >Confidential:   no
 > >Severity:       critical
 > >Priority:       high
 > >Responsible:    grant
 > >State:          open
 > >Class:          sw-bug
 > >Submitter-Id:   net
 > >Arrival-Date:   Thu Nov 17 10:50:00 +0000 2005
 > >Originator:     segv
 > >Release:        
 > >Organization:
 > >Environment:
 > SunOS ultra10 5.10 Generic sun4u sparc SUNW,Ultra-5_10
 > >Description:
 > After bootstrapping pkgsrc utilities with Sun Studio 11 compilers on UltraSparc machine, 'tar' command dies with SEGV and dumps a core. There are no problems when bootstrapping with GCC
 > >How-To-Repeat:
 > Bootstrap pkgsrc then use /usr/pkg/bin/tar to create a .tgz file.

 could you please provide a backtrace?

 grant.

From: segv@netctl.net
To: gnats-bugs@NetBSD.org
Cc: grant@NetBSD.org
Subject: Re: pkg/32097
Date: Fri, 18 Nov 2005 00:37:39 +0000

 OK dudes, I found the problem, it is in libnbcompat/vis.c file

 It has the following macro:

 #define MAKEEXTRALIST(flag, extra, orig)                                      \
 do {                                                                          \
         const char *o = orig;                                                 \
         char *e;                                                              \
         while (*o++)                                                          \
                 continue;                                                     \
         extra = alloca((size_t)((o - orig) + MAXEXTRAS));                     \
         for (o = orig, e = extra; (*e++ = *o++) != '\0';)                     \
                 continue;                                                     \
         e--;                                                                  \
         if (flag & VIS_SP) *e++ = ' ';                                        \
         if (flag & VIS_TAB) *e++ = '\t';                                      \
         if (flag & VIS_NL) *e++ = '\n';                                       \
         if ((flag & VIS_NOSLASH) == 0) *e++ = '\\';                           \
         *e = '\0';                                                            \
 } while (/*CONSTCOND*/0)


 and then later in the file the macro is called in the following way:

 MAKEEXTRALIST(flag, extra, "");

 the third argument to the macro causes problems, because it expands to empty
 string constants, which are stored at different addresses, so on a big-endian
 sparc machine:

 extra = alloca((size_t)((o - orig) + MAXEXTRAS));

 calls alloca() funcation, passing it a huge number, which overruns the stack
 and crashes the program.

 Below you can see the different behaviour you get with different compilers

 [ultra10] cat test.c
 #include <stdio.h>

 int main(void) 
 {
         printf("%lu\n", "" - "");
 }
 [ultra10] gcc test.c
 [ultra10] ./a.out
 0
 [ultra10] /opt/SUNWspro/bin/cc test.c
 [ultra10] ./a.out
 4294967292
 [ultra10]


 So, somebody has to fix vis.c file

 --- vis.c.orig  Fri Nov 18 00:16:26 2005
 +++ vis.c       Fri Nov 18 00:23:35 2005
 @@ -329,10 +329,11 @@

  {
         char *extra;
 +       const char *emptystr = "";

         _DIAGASSERT(dst != NULL);

 -       MAKEEXTRALIST(flag, extra, "");
 +       MAKEEXTRALIST(flag, extra, emptystr);
         if (flag & VIS_HTTPSTYLE)
                 HVIS(dst, c, flag, nextc, extra);
         else
 @@ -359,8 +360,9 @@
         int flag;
  {
         char *extra;
 +       const char *emptystr = "";

 -       MAKEEXTRALIST(flag, extra, "");
 +       MAKEEXTRALIST(flag, extra, emptystr);
         return (strsvis(dst, src, flag, extra));
  }

 @@ -373,7 +375,8 @@
         int flag;
  {
         char *extra;
 +       const char *emptystr = "";

 -       MAKEEXTRALIST(flag, extra, "");
 +       MAKEEXTRALIST(flag, extra, emptystr);
         return (strsvisx(dst, src, len, flag, extra));
  }

From: grant beattie <grant@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/32097 CVS commit: pkgsrc/pkgtools/libnbcompat/files
Date: Fri, 18 Nov 2005 03:31:11 +0000 (UTC)

 Module Name:	pkgsrc
 Committed By:	grant
 Date:		Fri Nov 18 03:31:11 UTC 2005

 Modified Files:
 	pkgsrc/pkgtools/libnbcompat/files: vis.c

 Log Message:
 pass const empty string to MAKEEXTRALIST macro instead of the
 anonymous empty string, which may be stored at a different address at
 the compiler's discretion.

 fixes tar(1) SEGV when built with Sunpro 11.

 from segv@netctl.net in PR pkg/32097.


 To generate a diff of this commit:
 cvs rdiff -r1.7 -r1.8 pkgsrc/pkgtools/libnbcompat/files/vis.c

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

From: grant beattie <grant@NetBSD.org>
To: gnats-bugs@netbsd.org
Cc: pkg-manager@netbsd.org, gnats-admin@netbsd.org,
	pkgsrc-bugs@netbsd.org
Subject: Re: pkg/32097
Date: Fri, 18 Nov 2005 14:32:18 +1100

 On Fri, Nov 18, 2005 at 12:38:01AM +0000, segv@netctl.net wrote:

 >  and then later in the file the macro is called in the following way:
 >  
 >  MAKEEXTRALIST(flag, extra, "");
 >  
 >  the third argument to the macro causes problems, because it expands to empty
 >  string constants, which are stored at different addresses, so on a big-endian
 >  sparc machine:
 >  
 >  extra = alloca((size_t)((o - orig) + MAXEXTRAS));
 >  
 >  calls alloca() funcation, passing it a huge number, which overruns the stack
 >  and crashes the program.

 excellent! thanks for tracking this down, I have committed your fix to
 vis.c.

 grant.

From: Martin Husemann <martin@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/32097 CVS commit: src/lib/libc/gen
Date: Fri, 18 Nov 2005 08:32:46 +0000 (UTC)

 Module Name:	src
 Committed By:	martin
 Date:		Fri Nov 18 08:32:46 UTC 2005

 Modified Files:
 	src/lib/libc/gen: vis.c

 Log Message:
 Make the MAKEEXTRALIST macro safe to be called with string literals as
 third argument - the old version relies on the compiler to use the same
 address for identical strings.

 Spotted by segv at netctl dot net in libnbcompat context, details
 in PR pkg/32097.


 To generate a diff of this commit:
 cvs rdiff -r1.33 -r1.34 src/lib/libc/gen/vis.c

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

Responsible-Changed-From-To: pkg-manager->solaris-pkg-people
Responsible-Changed-By: cube@netbsd.org
Responsible-Changed-When: Thu, 24 Nov 2005 02:09:31 +0000
Responsible-Changed-Why:
grant kind of handled it.  it might be possible to close that one.


State-Changed-From-To: open->closed
State-Changed-By: markd@netbsd.org
State-Changed-When: Tue, 27 Jun 2006 09:01:58 +0000
State-Changed-Why:
fixed some time ago.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.