During httpd setup I realized that duplicate location names are not
being detected at all, even though I remembered having seen a
corresponding piece of code in 'usr.sbin/httpd/parse.y' the other day.
As far as I understand, the comparison 's->srv_conf.id == srv_conf->id'
will never be true as the ID of any newly created location surely won't
be found in any location created before.

To check whether or not I was right, I recompiled httpd with DEBUG
options and tried to start the server with the following httpd.conf:

------------------------------------------------------------
server "testserver" {
        listen on 127.0.0.1 port www
        location "/foo" { block }
        location "/foo" { block }
}
------------------------------------------------------------

# httpd -vvd
startup
adding location "/foo" for "testserver[2]"
adding location "/foo" for "testserver[3]"
adding server "testserver[1]"
....
(httpd running)


I guess the intention was to only compare the new name with all other
location names available under the same parent server. I accomplished
this by applying the patch at the bottom of this message. After
recompiling, httpd startup terminates as expected.

# httpd -vvd
startup
adding location "/foo" for "testserver[2]"
/etc/httpd.conf:4: location "/foo" defined twice
.....
logger exiting, pid 98967
server exiting, pid 27723
server exiting, pid 78507
server exiting, pid 25743


Let me know if I got something wrong.

-------------------------------------------------------------------


Index: usr.sbin/httpd/parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.113
diff -u -p -r1.113 parse.y
--- usr.sbin/httpd/parse.y      28 Jun 2019 13:32:47 -0000      1.113
+++ usr.sbin/httpd/parse.y      7 Nov 2019 11:36:14 -0000
@@ -564,7 +564,8 @@ serveroptsl : LISTEN ON STRING opttls po

                        TAILQ_FOREACH(s, conf->sc_servers, srv_entry) {
                                if ((s->srv_conf.flags &
SRVFLAG_LOCATION) &&
-                                   s->srv_conf.id == srv_conf->id &&
+                                   s->srv_conf.parent_id ==
+                                   srv_conf->parent_id &&
                                    strcmp(s->srv_conf.location,
                                    srv_conf->location) == 0)
                                        break;

Reply via email to