From owner-freebsd-bugs@FreeBSD.ORG Sat May 1 18:30:24 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D2F2B16A4D3 for ; Sat, 1 May 2004 18:30:24 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7857B43D5E for ; Sat, 1 May 2004 18:30:16 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i421UGoH058613 for ; Sat, 1 May 2004 18:30:16 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i421UGiH058612; Sat, 1 May 2004 18:30:16 -0700 (PDT) (envelope-from gnats) Resent-Date: Sat, 1 May 2004 18:30:16 -0700 (PDT) Resent-Message-Id: <200405020130.i421UGiH058612@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, KS Braunsdorf Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E006316A4CF for ; 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 ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/66156: rpcgen generates a CPP macro that won't compile X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: KS Braunsdorf List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2004 01:30:25 -0000 >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; ! 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: