Date: Thu, 18 Jan 2001 20:00:02 -0800 (PST) From: Christopher Hall <hsw@acm.org> To: freebsd-bugs@FreeBSD.org Subject: Re: gnu/24445: ipnat does not parse its file properly Message-ID: <200101190400.f0J402h47258@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR gnu/24445; it has been noted by GNATS. From: Christopher Hall <hsw@acm.org> To: FreeBSD-gnats-submit@FreeBSD.ORG Cc: Subject: Re: gnu/24445: ipnat does not parse its file properly Date: Fri, 19 Jan 2001 11:54:00 +0800 setting 'proto' to NULL did not work completely as there some protocols e.g pop3s that have no corresponding udp number Since I am only redirecting tcp add: proto = "tcp"; to start of natparse instead. In message <200101190336.f0J3aVe43887@w40.tucheng.generalresources.com>, Christopher Hall writes: > >>Number: 24445 >>Category: gnu >>Synopsis: ipnat does not parse its file properly >>Confidential: no >>Severity: serious >>Priority: high >>Responsible: freebsd-bugs >>State: open >>Quarter: >>Keywords: >>Date-Required: >>Class: sw-bug >>Submitter-Id: current-users >>Arrival-Date: Thu Jan 18 19:40:01 PST 2001 >>Closed-Date: >>Last-Modified: >>Originator: Christopher Hall >>Release: FreeBSD 4.2-STABLE i386 >>Organization: >>Environment: > > 4.2-STABLE FreeBSD 4.2-STABLE #0: Thu Jan 18 13:15:08 CST 2001 > >>Description: > > Using the following configuration file: > > map fxp1 192.168.1.250/16 -> 1.2.3.4/32 portmap tcp/udp 40000:60000 > map fxp1 192.168.1.250/16 -> 1.2.3.4/32 > ##rdr fxp0 192.168.1.250/32 port 80 -> 4.5.6.7 port 80 > rdr fxp0 192.168.1.250/32 port http -> 4.5.6.7 port http > rdr fxp0 192.168.1.250/32 port https -> 4.5.6.7 port https > > >Get errors like this > > 4: unknown service "http". > 4: syntax error in "rdr" > 5: unknown service "https". > 5: syntax error in "rdr" > > can stop error by: > a) remove the '##' in line 3 > b) comment out line 1 > c) move line 1 to end of file > > >The problem is caused by a global variable in the file common.c >its definition is: char *proto = NULL; > >the file natparse.c uses the routine "portnum" to convert the >string "http" to a number > >'proto' is now pointing at the position in the line buffer where >the string "tcp/udp" used to be from line 1 of config file. > >Therefore the variable 'proto' points at the ".7" of the ip number when >parsing line 4. > >Using numeric port number does not access the global 'proto' variable in >portnum and later in natparse sets 'proto' pointing to static string "tcp" >for parsing the remaining lines. > >Any line that contains a protocol will set the 'proto' variable for >the next line. If this line is longer the 'proto' variable will be >pointing at an invalid string. > > >>How-To-Repeat: > > ipnat -f ipnat.conf (see above for for config file contents) > >>Fix: > > Don't use global variables like this! > > Should eliminate the global proto variable and pass the protocol > as a parameter to portnum. It looks like proto variable > is only shared by natparse.c parse.c and common.c. > > As far as I can tell only the 'rdr' command is affected, because > the protocol specified on the end of the line so the 'proto' variable > gets set too late. > > In natparse.c the is a section to decode the protocol, this would > have to be move before the first portnum call. However the method > of parsing the command line by using "cpp++;" to bump the toke pointer. > The easiest would be to change the syntax of the "rdr" command > from: > rdr le0 203.1.2.3/32 port 80 -> 203.1.2.3,203.1.2.4 port 80 tcp > to: > rdr tcp le0 203.1.2.3/32 port 80 -> 203.1.2.3,203.1.2.4 port 80 > > > Temporary Fix: > > Assume the protocol will be tcp or udp and that the same number > applies to both. > > To do this, just add the following line to the start of the > function natparse in natparse.c: > > proto = NULL; > > > Any better ideas? > >>Release-Note: >>Audit-Trail: >>Unformatted: > > >To Unsubscribe: send mail to majordomo@FreeBSD.org >with "unsubscribe freebsd-bugs" in the body of the message > --- Christopher Hall <atheist@generalresources.com> 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?200101190400.f0J402h47258>