Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 May 2004 20:26:12 -0500 (CDT)
From:      KS Braunsdorf <rpcgen@ksb.npcguild.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/66156: rpcgen generates a CPP macro that won't compile
Message-ID:  <200405020126.i421QCoB014591@proxy.npcguild.org>
Resent-Message-ID: <200405020130.i421UGiH058612@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         66156
>Category:       bin
>Synopsis:       rpcgen generates a CPP macro that won't compile
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 01 18:30:15 PDT 2004
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200405020126.i421QCoB014591>