From kneel@ishiboo.com  Wed Apr 22 00:56:47 1998
Received: from bleep.ishiboo.com (user11007@bleep.ishiboo.com [199.79.133.2])
          by hub.freebsd.org (8.8.8/8.8.8) with SMTP id AAA05794
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Apr 1998 00:56:44 GMT
          (envelope-from kneel@ishiboo.com)
Received: (qmail 10338 invoked by uid 1001); 22 Apr 1998 01:56:58 -0000
Message-Id: <19980422015657.16212.qmail@bleep.ishiboo.com>
Date: 22 Apr 1998 01:56:57 -0000
From: kneel@ishiboo.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: ipfw parsing errors

>Number:         6379
>Category:       bin
>Synopsis:       ipfw parsing is broken when taking rules from a file
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 21 18:00:01 PDT 1998
>Closed-Date:    Tue Apr 21 23:20:31 PDT 1998
>Last-Modified:  Tue Apr 21 23:20:49 PDT 1998
>Originator:     Neal Fachan
>Release:        All
>Organization:
Ishiboo!
>Environment:
>Description:

When ipfw reads its rules from an input file, the optind variable is
not reinitialized to 1 after calling getopt. This results in parsing
errors on all but the first rule. An added patch also allows '#'
comments at the end of a line.

>How-To-Repeat:

cat >> ipfw_rules << EOF
-f flush
show
EOF
ipfw ipfw_rules

>Fix:
	
--- ipfw.c.orig	Thu Apr 16 20:16:34 1998
+++ ipfw.c	Thu Apr 16 20:20:16 1998
@@ -1179,6 +1179,7 @@
 	/* Set the force flag for non-interactive processes */
 	do_force = !isatty(STDIN_FILENO);
 
+	optind = 1;
 	while ((ch = getopt(ac, av, "afqtN")) != -1)
 	switch(ch) {
 		case 'a':
@@ -1275,6 +1276,7 @@
 		if ((f = fopen(av[1], "r")) == NULL)
 			err(EX_UNAVAILABLE, "fopen: %s", av[1]);
 		while (fgets(buf, BUFSIZ, f)) {
+			char *p;
 
 			lineno++;
 			sprintf(linename, "Line %d", lineno);
@@ -1282,6 +1284,8 @@
 
 			if (*buf == '#')
 				continue;
+			if ((p = strchr(buf, '#')) != NULL)
+				*p = '\0';
 			for (i = 1, a = strtok(buf, WHITESP);
 			    a && i < MAX_ARGS; a = strtok(NULL, WHITESP), i++)
 				args[i] = a;


-- 
Neal Fachan         kneel@ishiboo.com
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Tue Apr 21 23:20:31 PDT 1998 
State-Changed-Why:  
committed, thanks! 
>Unformatted:
