From fuyuki@hadaly.org  Wed Mar 19 00:13:47 2003
Return-Path: <fuyuki@hadaly.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id ABF2837B401
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 19 Mar 2003 00:13:47 -0800 (PST)
Received: from t-mta7.odn.ne.jp (mfep7.odn.ne.jp [143.90.131.185])
	by mx1.FreeBSD.org (Postfix) with ESMTP id BEB9B43F3F
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 19 Mar 2003 00:13:46 -0800 (PST)
	(envelope-from fuyuki@hadaly.org)
Received: from hadaly.dyndns.org ([61.123.32.121]) by t-mta7.odn.ne.jp
          with ESMTP
          id <20030319081345967.ZXPC.21631.t-mta7.odn.ne.jp@mta7.odn.ne.jp>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Wed, 19 Mar 2003 17:13:45 +0900
Received: from hadaly.dyndns.org (localhost [127.0.0.1])
	by hadaly.dyndns.org (Postfix) with ESMTP id 78D4E20BF
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 19 Mar 2003 17:13:45 +0900 (JST)
Message-Id: <861y13bwp2.wl%fuyuki@hadaly.org>
Date: Wed, 19 Mar 2003 17:13:45 +0900
From: Kimura Fuyuki <fuyuki@hadaly.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: calendar(1) dumps core if there is ./calendar/

>Number:         50118
>Category:       bin
>Synopsis:       calendar(1) dumps core if there is ./calendar/
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          feedback
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 19 00:20:11 PST 2003
>Closed-Date:    
>Last-Modified:  Tue Feb 15 13:20:05 UTC 2011
>Originator:     Kimura Fuyuki
>Release:        FreeBSD 5.0-RELEASE-p4 i386
>Organization:
>Environment:
System: FreeBSD hadaly.dyndns.org 5.0-RELEASE-p4 FreeBSD 5.0-RELEASE-p4 #2: Fri Mar 7 13:26:51 JST 2003 root@hadaly.dyndns.org:/.2/obj/usr/src/sys/NS i386


	
>Description:
calendar(1) dumps core if there is a directory named "calendar" in the
current working directory.
	
>How-To-Repeat:
$ calendar
calendar: no calendar file: ``calendar''
$ mkdir calendar
$ calendar
cpp: Internal error: Segmentation fault (program tradcpp0)
Please submit a full bug report.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
	
>Fix:
Need some stat(2)s, e.g:

http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/calendar/io.c?rev=1.22&content-type=text/x-cvsweb-markup

But `f' mode for freopen looks nice for me:

http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/calendar/calendar.c?rev=1.27&content-type=text/x-cvsweb-markup
>Release-Note:
>Audit-Trail:

From: Mike Makonnen <mtm@identd.net>
To: Kimura Fuyuki <fuyuki@hadaly.org>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, Mark Murray <mark@grondar.org>
Subject: Re: bin/50118: calendar(1) dumps core if there is ./calendar/
Date: Wed, 19 Mar 2003 10:51:16 -0500

 On Wed, 19 Mar 2003 17:13:45 +0900
 Kimura Fuyuki <fuyuki@hadaly.org> wrote:
 
 > 
 > >Number:         50118
 > >Category:       bin
 > >Synopsis:       calendar(1) dumps core if there is ./calendar/
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       low
 > >Responsible:    freebsd-bugs
 > >State:          open
 > >Originator:     Kimura Fuyuki
 > >Release:        FreeBSD 5.0-RELEASE-p4 i386
 > System: FreeBSD hadaly.dyndns.org 5.0-RELEASE-p4 FreeBSD 5.0-RELEASE-p4 #2:
 > Fri Mar 7 13:26:51 JST 2003 root@hadaly.dyndns.org:/.2/obj/usr/src/sys/NS i386
 > 
 > 
 > 	
 > >Description:
 > calendar(1) dumps core if there is a directory named "calendar" in the
 > current working directory.
 > 	
 > >How-To-Repeat:
 > $ calendar
 > calendar: no calendar file: ``calendar''
 > $ mkdir calendar
 > $ calendar
 > cpp: Internal error: Segmentation fault (program tradcpp0)
 > Please submit a full bug report.
 > See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
 > 	
 > >Fix:
 > Need some stat(2)s, e.g:
 > 
 > http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/calendar/io.c?rev=1.22&content-type=text/x-cvsweb-markup
 > 
 > But `f' mode for freopen looks nice for me:
 > 
 > http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/calendar/calendar.c?rev=1.27&content-type=text/x-cvsweb-markup
 
 We don't support the 'f' mode and since it's non-standard I don't know if it has
 a chance of making it in. However, stat(2) will also work just fine, as you
 pointed out. Patch attached.
 
 -- 
 Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
 mtm@identd.net | Fingerprint: D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9
 
 Index: usr.bin/calendar/io.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/calendar/io.c,v
 retrieving revision 1.19
 diff -u -r1.19 io.c
 --- usr.bin/calendar/io.c	28 Jul 2002 13:46:09 -0000	1.19
 +++ usr.bin/calendar/io.c	19 Mar 2003 15:42:58 -0000
 @@ -241,20 +241,25 @@
  	struct stat sbuf;
  
  	/* open up calendar file as stdin */
 -	if (!freopen(calendarFile, "r", stdin)) {
 +	if (!freopen(calendarFile, "r", stdin) ||
 +	    stat(calendarFile, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)) {
  		if (doall) {
  		    if (chdir(calendarHomes[0]) != 0)
  			return (NULL);
  		    if (stat(calendarNoMail, &sbuf) == 0)
  		        return (NULL);
 -		    if (!freopen(calendarFile, "r", stdin))
 +		    if (!freopen(calendarFile, "r", stdin) ||
 +		        stat(calendarFile, &sbuf) == -1 ||
 +		        !S_ISREG(sbuf.st_mode))
  		        return (NULL);
  		} else {
  		        chdir(getenv("HOME"));
  			for (found = i = 0; i < sizeof(calendarHomes) /
  			    sizeof(calendarHomes[0]); i++)
  			    if (chdir(calendarHomes[i]) == 0 &&
 -			          freopen(calendarFile, "r", stdin)) {
 +			          freopen(calendarFile, "r", stdin) &&
 +				  stat(calendarFile, &sbuf) == 0 &&
 +				  S_ISREG(sbuf.st_mode)) {
  				    found = 1;
  				    break;
  			    }

From: Kimura Fuyuki <fuyuki@hadaly.org>
To: mtm@identd.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, mark@grondar.org
Subject: Re: bin/50118: calendar(1) dumps core if there is ./calendar/
Date: Thu, 20 Mar 2003 08:34:48 +0900

 At Wed, 19 Mar 2003 10:51:16 -0500,
 Mike Makonnen <mtm@identd.net> wrote:
 > 
 > We don't support the 'f' mode and since it's non-standard I don't know if it has
 > a chance of making it in. However, stat(2) will also work just fine, as you
 > pointed out. Patch attached.
 
 Your patch works fine for non-regular files, but I found another problem...
 
 # cd /usr/bin
 # ls -l calendar
 -r-xr-xr-x  1 root  wheel  20296 Mar 20 08:30 calendar
 # ./calendar
 cpp: Internal error: Segmentation fault (program tradcpp0)
 Please submit a full bug report.
 See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.

From: Mike Makonnen <mtm@identd.net>
To: Kimura Fuyuki <fuyuki@hadaly.org>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, mark@grondar.org
Subject: Re: bin/50118: calendar(1) dumps core if there is ./calendar/
Date: Wed, 19 Mar 2003 19:11:21 -0500

 On Thu, 20 Mar 2003 08:34:48 +0900
 Kimura Fuyuki <fuyuki@hadaly.org> wrote:
 
 > Your patch works fine for non-regular files, but I found another problem...
 > 
 > # cd /usr/bin
 > # ls -l calendar
 > -r-xr-xr-x  1 root  wheel  20296 Mar 20 08:30 calendar
 > # ./calendar
 > cpp: Internal error: Segmentation fault (program tradcpp0)
 > Please submit a full bug report.
 > See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
 
 hmm
 
 We could add more checks, but we can't keep going on like that everytime
 something makes it dump core like that. Besides, there might be legitimate
 reasons why the calendar file might not be a text file. I wonder if the fix lies
 in cpp...
 I'm not familiar with cpp, but I'll look into it.
 
 Cheers.
 -- 
 Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
 mtm@identd.net | Fingerprint: D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9
Responsible-Changed-From-To: freebsd-bugs->grog 
Responsible-Changed-By: kris 
Responsible-Changed-When: Thu Nov 6 19:06:56 PST 2003 
Responsible-Changed-Why:  
Assign to calendar maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=50118 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=4629 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me to take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=26658 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me to take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34497 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me to take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36501 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me to take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36960 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me to take this one. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=37387 
Responsible-Changed-From-To: grog->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 25 02:12:49 UTC 2007 
Responsible-Changed-Why:  
grog@ asked me to take this one. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=50118 
Responsible-Changed-From-To: edwin->freebsd-bugs 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Feb 14 10:27:36 UTC 2008 
Responsible-Changed-Why:  

Give back into the pool until later. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=50118 

From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/50118: calendar(1) dumps core if there is ./calendar/
Date: Sat, 21 Jun 2008 10:24:45 +0100 (BST)

 I can still recreate the coredump on 6.x when there is a "calendar" 
 directory in the current directory, but not a file.  On 7.x, neither cause 
 a core dump.  Although I believe the real fix is in cpp(1) and not 
 calendar(1), the patch in the PR is a step in the right direction, and 
 would at least mask the problems currently seen.
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Mar 1 00:59:02 UTC 2010 
Responsible-Changed-Why:  
I will track  it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=50118 
State-Changed-From-To: open->feedback 
State-Changed-By: arundel 
State-Changed-When: Tue Feb 15 13:11:40 UTC 2011 
State-Changed-Why:  
It seems a few changes to cpp(1) were added since this PR was submitted. I'm no 
longer able to replicate the issue under stable/7 and stable/8: 

cc1: error: stdout: No such file or directory 

...this is with calendar being a directory and a symlink. Haven't tested it with 
sockets, etc. though. Can this PR be closed then? 

PS: Got the same cc1 error when using clang(1) as compiler. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=50118 
>Unformatted:
