Skip to content

Commit

Permalink
Update saver pointer ht after tfw_http_msg_grow_hdr_tbl() calls
Browse files Browse the repository at this point in the history
When tfw_http_msg_grow_hdr_tbl() is called it relocates
the hm->ht, but all code around the call still uses the
previous pointer. Thus changes are written to previous table, not
current.
  • Loading branch information
vankoven committed Dec 31, 2019
1 parent 0d6e7c6 commit 1b15a89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 12 additions & 3 deletions tempesta_fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -2866,9 +2866,11 @@ __h2_req_hdrs(TfwHttpReq *req, const TfwStr *hdr, unsigned int hid, bool append)
* to delete.
*/
return 0;
if (unlikely(hid == ht->size))
if (unlikely(hid == ht->size)) {
if (tfw_http_msg_grow_hdr_tbl(hm))
return -ENOMEM;
ht = hm->h_tbl;
}
if (hid == ht->off) {
/*
* The raw header not found, but we have the new
Expand Down Expand Up @@ -2971,7 +2973,7 @@ tfw_h2_adjust_req(TfwHttpReq *req)
TfwHttpHdrTbl *ht = req->h_tbl;
bool auth = !TFW_STR_EMPTY(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY]);
bool host = !TFW_STR_EMPTY(&ht->tbl[TFW_HTTP_HDR_HOST]);
size_t pseudo_num = auth ? 4 : 3;
size_t pseudo_num;
TfwStr meth = {}, host_val = {}, *field, *end;
struct sk_buff *new_head = NULL, *old_head = NULL;
TfwMsgIter it;
Expand Down Expand Up @@ -3038,7 +3040,14 @@ tfw_h2_adjust_req(TfwHttpReq *req)
*/
if ((r = tfw_h2_req_set_loc_hdrs(req)))
return r;

/*
* tfw_h2_req_set_loc_hdrs() may realloc header table and user may
* defined headers modifications, even headers we rely on, recheck them.
*/
ht = req->h_tbl;
auth = !TFW_STR_EMPTY(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY]);
host = !TFW_STR_EMPTY(&ht->tbl[TFW_HTTP_HDR_HOST]);
pseudo_num = auth ? 4 : 3;
/*
* Calculate http1.1 headers size. H2 request contains pseudo headers
* that are represented in different way in the http1.1 requests.
Expand Down
8 changes: 6 additions & 2 deletions tempesta_fw/http_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,11 @@ tfw_http_msg_hdr_xfrm_str(TfwHttpMsg *hm, const TfwStr *hdr, unsigned int hid,
if (hid == ht->off && !s_val)
/* Not found, nothing to delete. */
return 0;
if (hid == ht->size)
if (hid == ht->size) {
if (tfw_http_msg_grow_hdr_tbl(hm))
return -ENOMEM;
ht = hm->h_tbl;
}
if (hid == ht->off)
++ht->off;
else
Expand Down Expand Up @@ -1097,9 +1099,11 @@ tfw_http_msg_hdr_add(TfwHttpMsg *hm, const TfwStr *hdr)

ht = hm->h_tbl;
hid = ht->off;
if (hid == ht->size)
if (hid == ht->size) {
if (tfw_http_msg_grow_hdr_tbl(hm))
return -ENOMEM;
ht = hm->h_tbl;
}
++ht->off;

return __hdr_add(hm, hdr, hid);
Expand Down
9 changes: 3 additions & 6 deletions tempesta_fw/t/unit/test_http_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,13 @@ set_tfw_str(TfwStr *str, const char *cstr)
static void
set_raw_hdr(const char *cstr)
{
unsigned int hid;
TfwHttpHdrTbl *h_tbl = test_req->h_tbl;
unsigned int hid = test_req->h_tbl->off;

hid = h_tbl->off;

if (hid == h_tbl->size &&
if (hid == test_req->h_tbl->size &&
tfw_http_msg_grow_hdr_tbl((TfwHttpMsg *)test_req))
return;

++h_tbl->off;
++test_req->h_tbl->off;

set_tfw_str(&test_req->h_tbl->tbl[hid], cstr);
}
Expand Down

0 comments on commit 1b15a89

Please sign in to comment.