diff options
author | Zhidao HONG <z.hong@f5.com> | 2021-08-02 12:30:38 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2021-08-02 12:30:38 +0800 |
commit | d16cf0416784db82147ee5aaad1054840d028e7d (patch) | |
tree | 1f4e96cbd7aa4c3623629d4fce9f5aa3eb57d507 | |
parent | db03dfad6745a7d87d784ac51ed2d52e1c50a557 (diff) | |
download | unit-d16cf0416784db82147ee5aaad1054840d028e7d.tar.gz unit-d16cf0416784db82147ee5aaad1054840d028e7d.tar.bz2 |
Router: fixed segmentation fault.
In the case that routes or upstreams is empty and the pass option is a variable.
If the resolved pass is routes or upstreams, a segment error occurred.
-rw-r--r-- | src/nxt_http_route.c | 4 | ||||
-rw-r--r-- | src/nxt_upstream.c | 4 | ||||
-rw-r--r-- | test/test_variables.py | 19 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index c38acdf3..065b3488 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -1567,6 +1567,10 @@ nxt_http_route_find(nxt_http_routes_t *routes, nxt_str_t *name, { nxt_http_route_t **route, **end; + if (routes == NULL) { + return NXT_DECLINED; + } + route = &routes->route[0]; end = route + routes->items; diff --git a/src/nxt_upstream.c b/src/nxt_upstream.c index 9f81b286..de9b1d49 100644 --- a/src/nxt_upstream.c +++ b/src/nxt_upstream.c @@ -78,6 +78,10 @@ nxt_upstream_find(nxt_upstreams_t *upstreams, nxt_str_t *name, uint32_t i, n; nxt_upstream_t *upstream; + if (upstreams == NULL) { + return NXT_DECLINED; + } + upstream = &upstreams->upstream[0]; n = upstreams->items; diff --git a/test/test_variables.py b/test/test_variables.py index 139d867e..d8547b7b 100644 --- a/test/test_variables.py +++ b/test/test_variables.py @@ -100,6 +100,25 @@ class TestVariables(TestApplicationProto): assert self.get(url='/1')['status'] == 200 assert self.get(url='/2')['status'] == 404 + def test_variables_empty(self): + def update_pass(prefix): + assert 'success' in self.conf( + { + "listeners": { + "*:7080": {"pass": prefix + "/$method"}, + }, + }, + ), 'variables empty' + + update_pass("routes"); + assert self.get(url='/1')['status'] == 404 + + update_pass("upstreams"); + assert self.get(url='/2')['status'] == 404 + + update_pass("applications"); + assert self.get(url='/3')['status'] == 404 + def test_variables_invalid(self): def check_variables(routes): assert 'error' in self.conf( |