Hello,

I think I've found an off-by-one bug in httpd: it cannot listen on port
65535 when the port is specified as a number (although it can listen on
it if specified as the string "65535", or if an appropriate line is
added to /etc/services and it's specified with that name).

$ uname -a
OpenBSD Meryl 6.1 GENERIC.MP#19 amd64

$ cat /etc/httpd.conf
server "default" {
  listen on egress port 65535
}

$ doas httpd -n
/etc/httpd.conf:2: invalid port: 65535
no actions, nothing to do


The above is on 6.1, but it looks like the problem still exists in CVS.

Below is a patch (or the possible start of one).  It's untested as I
cannot do a build and test it right now, but I think it's enough.  If
not, I hope it's at least a little helpful.  Let me know if there is
anything else I can do and I'll try to do it whenever I can.

Thanks,
Kris Katterjohn

Index: usr.sbin/httpd/parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.91
diff -u -p -r1.91 parse.y
--- usr.sbin/httpd/parse.y      11 Aug 2017 18:48:56 -0000      1.91
+++ usr.sbin/httpd/parse.y      18 Aug 2017 04:10:35 -0000
@@ -1118,7 +1118,7 @@ medianamesl       : numberstring                          
{
                ;
 
 port           : PORT NUMBER {
-                       if ($2 <= 0 || $2 >= (int)USHRT_MAX) {
+                       if ($2 <= 0 || $2 > (int)USHRT_MAX) {
                                yyerror("invalid port: %lld", $2);
                                YYERROR;
                        }

Reply via email to