From ksb@proxy.npcguild.org  Sat May  1 18:26:14 2004
Return-Path: <ksb@proxy.npcguild.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E006316A4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  1 May 2004 18:26:14 -0700 (PDT)
Received: from proxy.npcguild.org (rrcs-ma-24-56-87-2.biz.rr.com [24.56.87.2])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 060E843D3F
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  1 May 2004 18:26:14 -0700 (PDT)
	(envelope-from ksb@proxy.npcguild.org)
Received: from proxy.npcguild.org (ksb@localhost [127.0.0.1])
	by proxy.npcguild.org (8.12.11/8.12.11) with ESMTP id i421QDDU014592
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 1 May 2004 20:26:13 -0500 (CDT)
	(envelope-from ksb@proxy.npcguild.org)
Received: (from ksb@localhost)
	by proxy.npcguild.org (8.12.11/8.12.11/Submit) id i421QCoB014591;
	Sat, 1 May 2004 20:26:12 -0500 (CDT)
	(envelope-from ksb)
Message-Id: <200405020126.i421QCoB014591@proxy.npcguild.org>
Date: Sat, 1 May 2004 20:26:12 -0500 (CDT)
From: KS Braunsdorf <rpcgen@ksb.npcguild.org>
Reply-To: KS Braunsdorf <rpcgen@ksb.npcguild.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: rpcgen generates a CPP macro that won't compile
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         66156
>Category:       bin
>Synopsis:       rpcgen generates a CPP macro that won't compile
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    smkelly
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 01 18:30:15 PDT 2004
>Closed-Date:    Mon Sep 26 16:21:11 GMT 2005
>Last-Modified:  Mon Sep 26 16:21:11 GMT 2005
>Originator:     KS Braunsdorf
>Release:        FreeBSD 4.10-PRERELEASE i386
>Organization:
NonPlayer Character Guild
>Environment:
System: FreeBSD proxy.npcguild.org 4.10-PRERELEASE FreeBSD 4.10-PRERELEASE #1: Sat May 1 16:24:44 CDT 2004 ksb@proxy.npcguild.org:/usr/obj/usr/src/sys/GENERIC i386
	Any machine running FreeBSD 4.x or 5.x.

>Description:
	rpcgen emits CPP #ifndef code that won't compile, based on the
	input filename.  This bug is triggered in programs that use
	mkstemp(3) to build rpc specs, then feed them to rpcgen, as
	mkstemp has a penchant for putting "-" or other spew in the
	temporary filename.

>How-To-Repeat:
	Use rpcgen on a description file with a hyphen in the name
	(viz. f-blah.x).  Any valid rpcgen code will work, this is
	short enough:
		$ cat >f-blah.x <<\!
		const MAXNAMELEN = 255;
		typedef string nametype<MAXNAMELEN>;
		!

	Run rpcgen on the file
		$ rpcgen f-blah.x

	grep for "BLAH" in the output header file:
		$  grep BLAH *.h
		#ifndef _F-BLAH_H_RPCGEN
		#define _F-BLAH_H_RPCGEN
		#endif /* !_F-BLAH_H_RPCGEN */

>Fix:
	The patch below fixes this, and the case where the input
	rpcgen filename starts with a dot (.). I know that's really Poor
	Form, but "be liberal with what you accept" is still true.

--- /tmp/rpc_main.c	Sat May  1 18:33:26 2004
+++ ./rpc_main.c	Sat May  1 20:08:07 2004
@@ -222,5 +222,5 @@
 		if (tblflag) {
 			reinitialize();
-		t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
+			t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
 		}
 
@@ -503,10 +503,28 @@
 	filename = ((filename == 0) ? pathname : filename+1);
 	guard = strdup(filename);
-	/* convert to upper case */
-	tmp = guard;
-	while (*tmp) {
+	/* convert to a valid C macro name, and upper case
+	 * =~ m,[A-Za-z_][A-Za-z_0-9]*,   else map other chars to '_'.
+	 */
+	for (tmp = guard; '\000' != *tmp; ++tmp) {
 		if (islower(*tmp))
 			*tmp = toupper(*tmp);
-		tmp++;
+		else if (isupper(*tmp) || '_' == *tmp)
+			/* OK for C */;
+		else if (tmp == guard)
+			*tmp = '_';
+		else if (isdigit(*tmp))
+			/* OK for all but first character */;
+		else if ('.' == *tmp) {
+			*tmp = '\000';
+			break;
+		} else
+			*tmp = '_';
+	}
+	/* When the filename started with "." (wow, the is Poor Form)
+	 * lets put in the word "DOT" so we don't violate ANSI's reservation
+	 * of macros that start with "_" -- rpc at ksb.npcguild.org
+	 */
+	if ('\000' == *guard) {
+		guard = "DOT";
 	}
 	guard = extendfile(guard, "_H_RPCGEN");
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: smkelly 
State-Changed-When: Sat May 1 19:00:26 PDT 2004 
State-Changed-Why:  
Committed to HEAD. Will MFC when 4.10 settles down. Keep 'em coming. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66156 
Responsible-Changed-From-To: freebsd-bugs->smkelly 
Responsible-Changed-By: smkelly 
Responsible-Changed-When: Sat May 1 19:04:44 PDT 2004 
Responsible-Changed-Why:  
Will MFC in a few weeks. 

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

From: Matteo Riondato <rionda@gufi.org>
To: Gnats PR Database <freebsd-gnats-submit@freebsd.org>
Cc: smkelly@freebsd.org
Subject: Re: bin/66156: rpcgen generates a CPP macro that won't compile
Date: Sat, 9 Apr 2005 19:43:03 +0200

 --U1t7w//IUm8YcF8e
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 This was MFCed to RELENG_5 but not to RELENG_4.
 Thank you.
 Best Regards
 --=20
 Rionda aka Matteo Riondato
 Disinformato per default
 G.U.F.I. Staff Member (http://www.gufi.org)
 FreeSBIE Developer (http://www.freesbie.org)
 
 --U1t7w//IUm8YcF8e
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.0 (FreeBSD)
 
 iD8DBQFCWBQn2Mp4pR7Fa+wRAre+AJ4qHR/nJuDhTy8/NopxLQiyjerWPQCeMTRF
 jSSjCFHaOrBUUSuzd3B/7XU=
 =bjAP
 -----END PGP SIGNATURE-----
 
 --U1t7w//IUm8YcF8e--
State-Changed-From-To: patched->closed 
State-Changed-By: smkelly 
State-Changed-When: Mon Sep 26 16:21:01 GMT 2005 
State-Changed-Why:  
Close this. 

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