Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Feb 2000 23:27:38 -0500 (EST)
From:      "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/16900: Bad error flagging in natd(8) config file read
Message-ID:  <200002220427.XAA04355@cc942873-a.ewndsr1.nj.home.com>

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

>Number:         16900
>Category:       bin
>Synopsis:       Bad error flagging in natd(8) config file read
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 21 20:30:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Crist J. Clark
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
>Environment:

	Present in all versions of FreeBSD checked up to 3.4-STABLE.

>Description:

	natd(8) will choke and die on a configuration file if the last
line of the file does not end in a newline. It does not matter whether
the line is even a natd option. natd will bail if the last line is a
comment and does not end in a newline (which is how I found this).

	That in itself is not necessarily a bug. What is a bug is that
natd improperly flags the error as,

             natd: config line too long: <last line>

>How-To-Repeat:

	This will occur anytime a natd configuration file is valid
until the last line without a newline.

>Fix:
	
	The workaround is to realize natd is misinterpretting the
situation and put a newline in your config file.

	There are two ways to have natd properly handle this. (1)
Flag a file with no newline on the last line, or (2) accept a file
with no newline on the last line.

	Here is the patch for (1),

--- /usr/src/sbin/natd/natd.c   Fri Jan 28 04:02:05 2000
+++ natd.c      Mon Feb 21 23:03:36 2000
@@ -1263,7 +1263,10 @@
 
                ptr = strchr (buf, '\n');
-               if (!ptr)
-                       errx (1, "config line too long: %s", buf);
+               if (!ptr) {
+                       ptr = strchr (buf, '\0');
+                       if ( ptr && ( ( ptr - buf + 1 ) < sizeof (buf) ) )
+                              errx (1, "no newline at end of config file: %s", buf);
+                       else
+                              errx (1, "config line too long: %s", buf);
+               }
  
                *ptr = '\0';


	However, here is the patch for my preference, (2),

--- /usr/src/sbin/natd/natd.c   Fri Jan 28 04:02:05 2000
+++ natd.c      Mon Feb 21 23:12:32 2000
@@ -1262,8 +1262,11 @@
        while (fgets (buf, sizeof (buf), file)) {
 
                ptr = strchr (buf, '\n');
-               if (!ptr)
-                       errx (1, "config line too long: %s", buf);
+               if (!ptr) {
+                       ptr = strchr (buf, '\0');
+                       if ( ptr && ( ( ptr - buf + 1 ) == sizeof (buf) ) )
+                               errx (1, "config line too long: %s", buf);
+               }
 
                *ptr = '\0';


I tested a little, but they are quick fixes. I may have overlooked
something.

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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