Skip to content

Commit c14a33b

Browse files
authored
Merge pull request #1162 from tempesta-tech/ik-fix-uninited-var
fix #1147 : init frag variable before use.
2 parents 98a4ab4 + 96b8933 commit c14a33b

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

tempesta_fw/http.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ tfw_http_prep_redirect(TfwHttpMsg *resp, unsigned short status, TfwStr *rmark,
438438
tfw_http_prep_date(__TFW_STR_CH(&h_common_1, 1)->data);
439439

440440
ret = tfw_msg_write(&it, rh);
441-
ret = tfw_msg_write(&it, &h_common_1);
441+
ret |= tfw_msg_write(&it, &h_common_1);
442442
/*
443443
* HTTP/1.0 may have no host part, so we create relative URI.
444444
* See RFC 1945 9.3 and RFC 7231 7.1.2.
@@ -2787,8 +2787,6 @@ tfw_http_hm_drop_resp(TfwHttpResp *resp)
27872787
TfwHttpReq *req = resp->req;
27882788

27892789
tfw_connection_unlink_msg(resp->conn);
2790-
tfw_apm_update(((TfwServer *)resp->conn->peer)->apmref,
2791-
resp->jrxtstamp, resp->jrxtstamp - req->jtxtstamp);
27922790
tfw_http_conn_msg_free((TfwHttpMsg *)resp);
27932791
tfw_http_msg_free((TfwHttpMsg *)req);
27942792
}

tempesta_fw/msg.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@
3434
int
3535
tfw_msg_write(TfwMsgIter *it, const TfwStr *data)
3636
{
37-
char *p;
3837
const TfwStr *c, *end;
39-
skb_frag_t *frag;
40-
unsigned int c_off = 0, f_size, c_size, f_room, n_copy;
4138

4239
BUG_ON(TFW_STR_DUP(data));
40+
if (WARN_ON_ONCE(it->frag >= skb_shinfo(it->skb)->nr_frags))
41+
return -E2BIG;
42+
4343
TFW_STR_FOR_EACH_CHUNK(c, data, end) {
44+
char *p;
45+
unsigned int c_off = 0, c_size, f_room, n_copy;
4446
this_chunk:
45-
if (!frag)
46-
return -E2BIG;
4747

4848
c_size = c->len - c_off;
4949
if (it->frag >= 0) {
50-
frag = &skb_shinfo(it->skb)->frags[it->frag];
50+
unsigned int f_size;
51+
skb_frag_t *frag = &skb_shinfo(it->skb)->frags[it->frag];
52+
5153
f_size = skb_frag_size(frag);
5254
f_room = PAGE_SIZE - frag->page_offset - f_size;
5355
p = (char *)skb_frag_address(frag) + f_size;
@@ -62,24 +64,26 @@ tfw_msg_write(TfwMsgIter *it, const TfwStr *data)
6264

6365
memcpy_fast(p, c->data + c_off, n_copy);
6466

65-
if (c_size < f_room) {
66-
/*
67-
* The chunk fits in the SKB fragment with room
68-
* to spare. Stay in the same SKB fragment, switch
69-
* to next chunk of the string.
70-
*/
71-
c_off = 0;
72-
} else {
73-
frag = ss_skb_frag_next(&it->skb, it->skb_head,
74-
&it->frag);
67+
/*
68+
* The chunk occupied all the spare space in the SKB fragment,
69+
* switch to the next fragment.
70+
*/
71+
if (c_size >= f_room) {
72+
skb_frag_t *frag = ss_skb_frag_next(&it->skb,
73+
it->skb_head,
74+
&it->frag);
75+
if (WARN_ON_ONCE(!frag
76+
&& ((c_size != f_room)
77+
|| (c + 1 < end))))
78+
{
79+
return -E2BIG;
80+
}
7581
/*
76-
* If all data from the chunk has been copied,
77-
* then switch to the next chunk. Otherwise,
78-
* stay in the current chunk.
82+
* Not all data from the chunk has been copied,
83+
* stay in the current chunk and copy the rest to the
84+
* next fragment.
7985
*/
80-
if (c_size == f_room) {
81-
c_off = 0;
82-
} else {
86+
if (c_size != f_room) {
8387
c_off += n_copy;
8488
goto this_chunk;
8589
}

tempesta_fw/ss_skb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ ss_skb_frag_next(struct sk_buff **skb, const struct sk_buff *skb_head, int *f)
129129
}
130130

131131
*skb = (*skb)->next;
132+
*f = 0;
132133
if (*skb == skb_head || !skb_shinfo(*skb)->nr_frags)
133134
return NULL;
134-
*f = 0;
135135
return &skb_shinfo(*skb)->frags[0];
136136
}
137137

0 commit comments

Comments
 (0)