NetBSD Problem Report #594

From gnats  Mon Nov 28 22:25:38 1994
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id WAA06117 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Mon, 28 Nov 1994 22:25:38 -0800
Message-Id: <199411290612.BAA02185@CHUQ.FAC.CS.CMU.EDU>
Date: Tue, 29 Nov 1994 01:12:05 -0500
From: chs@cs.cmu.edu
Reply-To: chs@cs.cmu.edu
To: gnats-bugs@NetBSD.ORG
Subject: too many fopen()s can cause bus errors
X-Send-Pr-Version: 3.2

>Number:         594
>Category:       lib
>Synopsis:       too many fopen()s can cause bus errors
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    gnats-admin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 28 22:35:02 +0000 1994
>Closed-Date:    Thu Dec 08 22:58:57 +0000 1994
>Last-Modified:  
>Originator:     Chuck Silvers
>Release:        1.0
>Organization:
CMU
>Environment:
System: NetBSD chuq.fac.cs.cmu.edu 1.0 NetBSD 1.0 (SPARC) #39: Fri Nov 18 02:33:07 EST 1994 chs@chuq.fac.cs.cmu.edu:/usr/src/sys/arch/sparc/compile/SPARC sparc


>Description:

In moreglue() in lib/libc/stdio/findfp.c,  the structure assignment
                *p++ = empty;
can cause a bus error if p doesn't happen to be properly aligned.
It never is on (for example) the sparc.


>How-To-Repeat:

Compile and run the following program on an architecture where
ALIGN(sizeof(struct glue)) != sizeof(struct glue)
(with "struct glue" from lib/libc/stdio/glue.h).
The sparc and pmax are the only architectures that I can see
that this is true of just from glancing at their machine/param.h's.

main()
{
    int i;
    for (i = 1; i < 50; i++) {
        (void) fopen("/dev/null", "r");
        printf("%d\n", i);
    }
}

This bus-errors after 17 iterations on my sparc, which is the first time
moreglue() would be called.

>Fix:

*** findfp.c.orig	Tue Nov 29 00:37:58 1994
--- /usr/src/lib/libc/stdio/findfp.c	Tue Nov 29 00:41:54 1994
***************
*** 39,44 ****
--- 39,45 ----
  static char *rcsid = "$Id: findfp.c,v 1.4 1993/12/31 19:14:12 jtc Exp $";
  #endif /* LIBC_SCCS and not lint */

+ #include <sys/param.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <errno.h>
***************
*** 74,83 ****
  	register FILE *p;
  	static FILE empty;

! 	g = (struct glue *)malloc(sizeof(*g) + n * sizeof(FILE));
  	if (g == NULL)
  		return (NULL);
! 	p = (FILE *)(g + 1);
  	g->next = NULL;
  	g->niobs = n;
  	g->iobs = p;
--- 75,84 ----
  	register FILE *p;
  	static FILE empty;

! 	g = (struct glue *)malloc(sizeof(*g) + n * sizeof(FILE) + ALIGNBYTES);
  	if (g == NULL)
  		return (NULL);
! 	p = (FILE *)ALIGN(g + 1);
  	g->next = NULL;
  	g->niobs = n;
  	g->iobs = p;
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: cgd 
State-Changed-When: Thu Dec 8 14:58:57 PST 1994 
State-Changed-Why:  
fixed.  (functionally identical patch applied.) 
>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.