Skip to content

Commit 4891350

Browse files
Fix error handling
We should immediately return in case of error not use '|=' to collect result.
1 parent 14cd37b commit 4891350

File tree

1 file changed

+82
-25
lines changed

1 file changed

+82
-25
lines changed

fw/http.c

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,9 +3338,14 @@ __tfw_http_add_hdr_via(TfwHttpMsg *hm, int http_version, bool from_cache)
33383338
TfwStr crlf = { .data = S_CRLF, .len = SLEN(S_CRLF) };
33393339

33403340
r = tfw_http_msg_expand_data(&mit->iter, skb_head, &rh, NULL);
3341-
r |= tfw_http_msg_expand_data(&mit->iter, skb_head,
3341+
if (unlikely(r))
3342+
goto finish;
3343+
3344+
r = tfw_http_msg_expand_data(&mit->iter, skb_head,
33423345
&crlf, NULL);
33433346
}
3347+
3348+
finish:
33443349
if (r)
33453350
T_ERR("Unable to add via: header to msg [%p]\n", hm);
33463351
else
@@ -3523,13 +3528,17 @@ tfw_h1_set_loc_hdrs(TfwHttpMsg *hm, bool is_resp, bool from_cache)
35233528
/* h_mdf->eolen is ignored, add explicit CRLF. */
35243529
r = tfw_http_msg_expand_data(&mit->iter, skb_head,
35253530
&h_mdf, NULL);
3526-
r |= tfw_http_msg_expand_data(&mit->iter, skb_head,
3531+
if (unlikely(r))
3532+
goto finish;
3533+
3534+
r = tfw_http_msg_expand_data(&mit->iter, skb_head,
35273535
&crlf, NULL);
35283536
} else {
35293537
r = tfw_http_msg_hdr_xfrm_str(hm, &h_mdf, d->hid,
35303538
d->append);
35313539
}
35323540

3541+
finish:
35333542
if (r) {
35343543
T_ERR("can't update location-specific header in msg %p\n",
35353544
hm);
@@ -3861,11 +3870,18 @@ write_merged_cookie_headers(TfwStr *hdr, TfwMsgIter *it)
38613870
hval.nchunks--;
38623871
hval.len -= chunk->len;
38633872
}
3864-
r |= tfw_msg_write(it, cookie_dlm);
3865-
r |= tfw_msg_write(it, &hval);
3873+
r = tfw_msg_write(it, cookie_dlm);
3874+
if (unlikely(r))
3875+
return r;
3876+
3877+
r = tfw_msg_write(it, &hval);
3878+
if (unlikely(r))
3879+
return r;
3880+
38663881
cookie_dlm = &val_dlm;
38673882
}
3868-
return r | tfw_msg_write(it, &crlf);
3883+
3884+
return tfw_msg_write(it, &crlf);
38693885
}
38703886

38713887
static int
@@ -4072,20 +4088,40 @@ tfw_h2_adjust_req(TfwHttpReq *req)
40724088

40734089
if (WARN_ON_ONCE(h1_hdrs_sz < 0))
40744090
return -EINVAL;
4075-
if ((r = tfw_msg_iter_setup(&it, &new_head, h1_hdrs_sz, 0)))
4091+
4092+
r = tfw_msg_iter_setup(&it, &new_head, h1_hdrs_sz, 0);
4093+
if (unlikely(r))
40764094
return r;
40774095

40784096
/* First line. */
40794097
r = __h2_write_method(req, &it);
4080-
r |= tfw_msg_write(&it, &sp);
4081-
r |= tfw_msg_write(&it, &req->uri_path);
4082-
r |= tfw_msg_write(&it, &fl_end); /* start of Host: header */
4098+
if (unlikely(r))
4099+
goto err;
4100+
4101+
r = tfw_msg_write(&it, &sp);
4102+
if (unlikely(r))
4103+
goto err;
4104+
4105+
r = tfw_msg_write(&it, &req->uri_path);
4106+
if (unlikely(r))
4107+
goto err;
4108+
4109+
r = tfw_msg_write(&it, &fl_end); /* start of Host: header */
4110+
if (unlikely(r))
4111+
goto err;
4112+
40834113
if (auth)
40844114
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY], &host_val);
40854115
else if (host)
40864116
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_HOST], &host_val);
4087-
r |= tfw_msg_write(&it, &host_val);
4088-
r |= tfw_msg_write(&it, &crlf);
4117+
4118+
r = tfw_msg_write(&it, &host_val);
4119+
if (unlikely(r))
4120+
goto err;
4121+
4122+
r = tfw_msg_write(&it, &crlf);
4123+
if (unlikely(r))
4124+
goto err;
40894125

40904126
/* Skip host header: it's already written. */
40914127
FOR_EACH_HDR_FIELD_FROM(field, end, req, TFW_HTTP_HDR_REGULAR) {
@@ -4096,19 +4132,25 @@ tfw_h2_adjust_req(TfwHttpReq *req)
40964132
case TFW_HTTP_HDR_HOST:
40974133
continue; /* Already written. */
40984134
case TFW_HTTP_HDR_X_FORWARDED_FOR:
4099-
r |= tfw_msg_write(&it, &h_xff);
4135+
r = tfw_msg_write(&it, &h_xff);
4136+
if (unlikely(r))
4137+
goto err;
41004138
continue;
41014139
case TFW_HTTP_HDR_CONTENT_TYPE:
41024140
if (h_ct_replace) {
4103-
r |= tfw_msg_write(&it, &h_ct);
4141+
r = tfw_msg_write(&it, &h_ct);
4142+
if (unlikely(r))
4143+
goto err;
41044144
continue;
41054145
}
41064146
break;
41074147
case TFW_HTTP_HDR_COOKIE:
41084148
if (!TFW_STR_DUP(field))
41094149
break;
4110-
r |= write_merged_cookie_headers(
4150+
r = write_merged_cookie_headers(
41114151
&ht->tbl[TFW_HTTP_HDR_COOKIE], &it);
4152+
if (unlikely(r))
4153+
goto err;
41124154
continue;
41134155
default:
41144156
break;
@@ -4131,20 +4173,33 @@ tfw_h2_adjust_req(TfwHttpReq *req)
41314173
hval.nchunks++;
41324174
hval.len += chunk->len;
41334175
}
4134-
r |= tfw_msg_write(&it, &hval);
4135-
r |= tfw_msg_write(&it, &dlm);
4176+
r = tfw_msg_write(&it, &hval);
4177+
if (unlikely(r))
4178+
goto err;
4179+
r = tfw_msg_write(&it, &dlm);
4180+
if (unlikely(r))
4181+
goto err;
4182+
41364183
hval.chunks += hval.nchunks;
41374184
hval.nchunks = dup->nchunks - hval.nchunks;
41384185
hval.len = dup->len - hval.len;
4139-
r |= tfw_msg_write(&it, &hval);
41404186

4141-
r |= tfw_msg_write(&it, &crlf);
4187+
r = tfw_msg_write(&it, &hval);
4188+
if (unlikely(r))
4189+
goto err;
4190+
4191+
r = tfw_msg_write(&it, &crlf);
4192+
if (unlikely(r))
4193+
goto err;
41424194
}
41434195
if (unlikely(r))
41444196
goto err;
41454197
}
41464198

4147-
r |= tfw_msg_write(&it, &h_via);
4199+
r = tfw_msg_write(&it, &h_via);
4200+
if (unlikely(r))
4201+
goto err;
4202+
41484203
if (need_cl) {
41494204
h_cl = (TfwStr) {
41504205
.chunks = (TfwStr []) {
@@ -4156,11 +4211,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
41564211
.len = cl_len,
41574212
.nchunks = 4
41584213
};
4159-
r |= tfw_msg_write(&it, &h_cl);
4214+
r = tfw_msg_write(&it, &h_cl);
4215+
if (unlikely(r))
4216+
goto err;
41604217
}
41614218
/* Finally close headers. */
4162-
r |= tfw_msg_write(&it, &crlf);
4163-
4219+
r = tfw_msg_write(&it, &crlf);
41644220
if (unlikely(r))
41654221
goto err;
41664222

@@ -4208,11 +4264,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
42084264
}
42094265

42104266
return 0;
4267+
42114268
err:
42124269
ss_skb_queue_purge(&new_head);
4213-
T_DBG3("%s: req [%p] convertation to http1.1 has failed\n",
4214-
__func__, req);
4215-
return -EINVAL;
4270+
T_DBG3("%s: req [%px] convertation to http1.1 has failed"
4271+
" with result (%d)\n", __func__, req, r);
4272+
return r;
42164273
}
42174274

42184275
/*

0 commit comments

Comments
 (0)