0ebb58e380fff365ba431ff00d8105962a12e55a
[openwrt-packages.git] /
1 commit 2351ca211d655c1be9ef6d62880899102134266d
2 Author: Christopher Faulet <cfaulet@haproxy.com>
3 Date:   Fri Jul 26 16:31:34 2019 +0200
4
5     BUG/MINOR: hlua: Only execute functions of HTTP class if the txn is HTTP ready
6     
7     The flag HLUA_TXN_HTTP_RDY was added in the previous commit to know when a
8     function is called for a channel with a valid HTTP message or not. Of course it
9     also depends on the calling direction. In this commit, we allow the execution of
10     functions of the HTTP class only if this flag is set.
11     
12     Nobody seems to use them from an unsupported context (for instance, trying to
13     set an HTTP header from a tcp-request rule). But it remains a bug leading to
14     undefined behaviors or crashes.
15     
16     This patch may be backported to all versions since the 1.6. It depends on the
17     commits "MINOR: hlua: Add a flag on the lua txn to know in which context it can
18     be used" and "MINOR: hlua: Don't set request analyzers on response channel for
19     lua actions".
20     
21     (cherry picked from commit 301eff8e215d5dc7130e1ebacd7cf8da09a4f643)
22     Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
23
24 diff --git a/src/hlua.c b/src/hlua.c
25 index d37e3c61..4d92fa44 100644
26 --- a/src/hlua.c
27 +++ b/src/hlua.c
28 @@ -5346,7 +5346,7 @@ __LJMP static int hlua_http_req_get_headers(lua_State *L)
29         MAY_LJMP(check_args(L, 1, "req_get_headers"));
30         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
31  
32 -       if (htxn->dir != SMP_OPT_DIR_REQ)
33 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
34                 WILL_LJMP(lua_error(L));
35  
36         return hlua_http_get_headers(L, htxn, &htxn->s->txn->req);
37 @@ -5359,7 +5359,7 @@ __LJMP static int hlua_http_res_get_headers(lua_State *L)
38         MAY_LJMP(check_args(L, 1, "res_get_headers"));
39         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
40  
41 -       if (htxn->dir != SMP_OPT_DIR_RES)
42 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
43                 WILL_LJMP(lua_error(L));
44  
45         return hlua_http_get_headers(L, htxn, &htxn->s->txn->rsp);
46 @@ -5399,7 +5399,7 @@ __LJMP static int hlua_http_req_rep_hdr(lua_State *L)
47         MAY_LJMP(check_args(L, 4, "req_rep_hdr"));
48         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
49  
50 -       if (htxn->dir != SMP_OPT_DIR_REQ)
51 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
52                 WILL_LJMP(lua_error(L));
53  
54         return MAY_LJMP(hlua_http_rep_hdr(L, htxn, &htxn->s->txn->req, ACT_HTTP_REPLACE_HDR));
55 @@ -5412,7 +5412,7 @@ __LJMP static int hlua_http_res_rep_hdr(lua_State *L)
56         MAY_LJMP(check_args(L, 4, "res_rep_hdr"));
57         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
58  
59 -       if (htxn->dir != SMP_OPT_DIR_RES)
60 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
61                 WILL_LJMP(lua_error(L));
62  
63         return MAY_LJMP(hlua_http_rep_hdr(L, htxn, &htxn->s->txn->rsp, ACT_HTTP_REPLACE_HDR));
64 @@ -5425,7 +5425,7 @@ __LJMP static int hlua_http_req_rep_val(lua_State *L)
65         MAY_LJMP(check_args(L, 4, "req_rep_hdr"));
66         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
67  
68 -       if (htxn->dir != SMP_OPT_DIR_REQ)
69 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
70                 WILL_LJMP(lua_error(L));
71  
72         return MAY_LJMP(hlua_http_rep_hdr(L, htxn, &htxn->s->txn->req, ACT_HTTP_REPLACE_VAL));
73 @@ -5438,7 +5438,7 @@ __LJMP static int hlua_http_res_rep_val(lua_State *L)
74         MAY_LJMP(check_args(L, 4, "res_rep_val"));
75         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
76  
77 -       if (htxn->dir != SMP_OPT_DIR_RES)
78 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
79                 WILL_LJMP(lua_error(L));
80  
81         return MAY_LJMP(hlua_http_rep_hdr(L, htxn, &htxn->s->txn->rsp, ACT_HTTP_REPLACE_VAL));
82 @@ -5480,7 +5480,7 @@ __LJMP static int hlua_http_req_del_hdr(lua_State *L)
83         MAY_LJMP(check_args(L, 2, "req_del_hdr"));
84         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
85  
86 -       if (htxn->dir != SMP_OPT_DIR_REQ)
87 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
88                 WILL_LJMP(lua_error(L));
89  
90         return hlua_http_del_hdr(L, htxn, &htxn->s->txn->req);
91 @@ -5493,7 +5493,7 @@ __LJMP static int hlua_http_res_del_hdr(lua_State *L)
92         MAY_LJMP(check_args(L, 2, "res_del_hdr"));
93         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
94  
95 -       if (htxn->dir != SMP_OPT_DIR_RES)
96 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
97                 WILL_LJMP(lua_error(L));
98  
99         return hlua_http_del_hdr(L, htxn, &htxn->s->txn->rsp);
100 @@ -5547,7 +5547,7 @@ __LJMP static int hlua_http_req_add_hdr(lua_State *L)
101         MAY_LJMP(check_args(L, 3, "req_add_hdr"));
102         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
103  
104 -       if (htxn->dir != SMP_OPT_DIR_REQ)
105 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
106                 WILL_LJMP(lua_error(L));
107  
108         return hlua_http_add_hdr(L, htxn, &htxn->s->txn->req);
109 @@ -5560,7 +5560,7 @@ __LJMP static int hlua_http_res_add_hdr(lua_State *L)
110         MAY_LJMP(check_args(L, 3, "res_add_hdr"));
111         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
112  
113 -       if (htxn->dir != SMP_OPT_DIR_RES)
114 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
115                 WILL_LJMP(lua_error(L));
116  
117         return hlua_http_add_hdr(L, htxn, &htxn->s->txn->rsp);
118 @@ -5573,7 +5573,7 @@ static int hlua_http_req_set_hdr(lua_State *L)
119         MAY_LJMP(check_args(L, 3, "req_set_hdr"));
120         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
121  
122 -       if (htxn->dir != SMP_OPT_DIR_REQ)
123 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
124                 WILL_LJMP(lua_error(L));
125  
126         hlua_http_del_hdr(L, htxn, &htxn->s->txn->req);
127 @@ -5587,7 +5587,7 @@ static int hlua_http_res_set_hdr(lua_State *L)
128         MAY_LJMP(check_args(L, 3, "res_set_hdr"));
129         htxn = MAY_LJMP(hlua_checkhttp(L, 1));
130  
131 -       if (htxn->dir != SMP_OPT_DIR_RES)
132 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
133                 WILL_LJMP(lua_error(L));
134  
135         hlua_http_del_hdr(L, htxn, &htxn->s->txn->rsp);
136 @@ -5601,7 +5601,7 @@ static int hlua_http_req_set_meth(lua_State *L)
137         size_t name_len;
138         const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
139  
140 -       if (htxn->dir != SMP_OPT_DIR_REQ)
141 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
142                 WILL_LJMP(lua_error(L));
143  
144         lua_pushboolean(L, http_replace_req_line(0, name, name_len, htxn->p, htxn->s) != -1);
145 @@ -5615,7 +5615,7 @@ static int hlua_http_req_set_path(lua_State *L)
146         size_t name_len;
147         const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
148  
149 -       if (htxn->dir != SMP_OPT_DIR_REQ)
150 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
151                 WILL_LJMP(lua_error(L));
152  
153         lua_pushboolean(L, http_replace_req_line(1, name, name_len, htxn->p, htxn->s) != -1);
154 @@ -5629,7 +5629,7 @@ static int hlua_http_req_set_query(lua_State *L)
155         size_t name_len;
156         const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
157  
158 -       if (htxn->dir != SMP_OPT_DIR_REQ)
159 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
160                 WILL_LJMP(lua_error(L));
161  
162         /* Check length. */
163 @@ -5656,7 +5656,7 @@ static int hlua_http_req_set_uri(lua_State *L)
164         size_t name_len;
165         const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
166  
167 -       if (htxn->dir != SMP_OPT_DIR_REQ)
168 +       if (htxn->dir != SMP_OPT_DIR_REQ || !(htxn->flags & HLUA_TXN_HTTP_RDY))
169                 WILL_LJMP(lua_error(L));
170  
171         lua_pushboolean(L, http_replace_req_line(3, name, name_len, htxn->p, htxn->s) != -1);
172 @@ -5670,7 +5670,7 @@ static int hlua_http_res_set_status(lua_State *L)
173         unsigned int code = MAY_LJMP(luaL_checkinteger(L, 2));
174         const char *reason = MAY_LJMP(luaL_optlstring(L, 3, NULL, NULL));
175  
176 -       if (htxn->dir != SMP_OPT_DIR_RES)
177 +       if (htxn->dir != SMP_OPT_DIR_RES || !(htxn->flags & HLUA_TXN_HTTP_RDY))
178                 WILL_LJMP(lua_error(L));
179  
180         http_set_status(code, reason, htxn->s);
git clone https://git.99rst.org/PROJECT