summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOisin Canty <o.canty@f5.com>2021-08-05 16:00:01 +0000
committerOisin Canty <o.canty@f5.com>2021-08-05 16:00:01 +0000
commit60cf1399611ae1b2728492c94ff57a4a044774b4 (patch)
tree9ec34d4b8c018fcc46a24a42b8b4fd91618f5f1e
parent44fe31dc6198e7a6fd752d6cdb7e51be73f6d8eb (diff)
downloadunit-60cf1399611ae1b2728492c94ff57a4a044774b4.tar.gz
unit-60cf1399611ae1b2728492c94ff57a4a044774b4.tar.bz2
Router: fixed crash when matching an empty address pattern array.
A crash would occur when the router tried to match an against an empty address pattern array. The following configuration was used to reproduce the issue: { "listeners": { "127.0.0.1:8082": { "pass": "routes" } }, "routes": [ { "match": { "source": [] }, "action": { "return": 200 } } ] }
Diffstat (limited to '')
-rw-r--r--docs/changes.xml7
-rw-r--r--src/nxt_http_route.c5
-rw-r--r--test/test_routing.py4
3 files changed, 16 insertions, 0 deletions
diff --git a/docs/changes.xml b/docs/changes.xml
index 63c52633..e183f907 100644
--- a/docs/changes.xml
+++ b/docs/changes.xml
@@ -99,6 +99,13 @@ or "upstreams" using a variable "pass" option.
</para>
</change>
+<change type="bugfix">
+<para>
+the router process crashed while matching a request to an empty array of
+source or destination address patterns.
+</para>
+</change>
+
</changes>
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index 065b3488..b330796f 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -1936,6 +1936,11 @@ nxt_http_route_addr_rule(nxt_http_request_t *r,
nxt_http_route_addr_pattern_t *p;
n = addr_rule->items;
+
+ if (n == 0) {
+ return 0;
+ }
+
p = &addr_rule->addr_pattern[0] - 1;
do {
diff --git a/test/test_routing.py b/test/test_routing.py
index eaa0a134..ef5622c2 100644
--- a/test/test_routing.py
+++ b/test/test_routing.py
@@ -1751,6 +1751,10 @@ class TestRouting(TestApplicationProto):
self.route_match_invalid({"source": "*:1-a"})
self.route_match_invalid({"source": "*:65536"})
+ def test_routes_match_source_none(self):
+ self.route_match({"source": []})
+ assert self.get()['status'] == 404, 'source none'
+
def test_routes_match_destination(self):
assert 'success' in self.conf(
{"*:7080": {"pass": "routes"}, "*:7081": {"pass": "routes"}},