@@ -3338,9 +3338,14 @@ __tfw_http_add_hdr_via(TfwHttpMsg *hm, int http_version, bool from_cache)
3338
3338
TfwStr crlf = { .data = S_CRLF , .len = SLEN (S_CRLF ) };
3339
3339
3340
3340
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 ,
3342
3345
& crlf , NULL );
3343
3346
}
3347
+
3348
+ finish :
3344
3349
if (r )
3345
3350
T_ERR ("Unable to add via: header to msg [%p]\n" , hm );
3346
3351
else
@@ -3523,13 +3528,17 @@ tfw_h1_set_loc_hdrs(TfwHttpMsg *hm, bool is_resp, bool from_cache)
3523
3528
/* h_mdf->eolen is ignored, add explicit CRLF. */
3524
3529
r = tfw_http_msg_expand_data (& mit -> iter , skb_head ,
3525
3530
& 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 ,
3527
3535
& crlf , NULL );
3528
3536
} else {
3529
3537
r = tfw_http_msg_hdr_xfrm_str (hm , & h_mdf , d -> hid ,
3530
3538
d -> append );
3531
3539
}
3532
3540
3541
+ finish :
3533
3542
if (r ) {
3534
3543
T_ERR ("can't update location-specific header in msg %p\n" ,
3535
3544
hm );
@@ -3861,11 +3870,18 @@ write_merged_cookie_headers(TfwStr *hdr, TfwMsgIter *it)
3861
3870
hval .nchunks -- ;
3862
3871
hval .len -= chunk -> len ;
3863
3872
}
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
+
3866
3881
cookie_dlm = & val_dlm ;
3867
3882
}
3868
- return r | tfw_msg_write (it , & crlf );
3883
+
3884
+ return tfw_msg_write (it , & crlf );
3869
3885
}
3870
3886
3871
3887
static int
@@ -4072,20 +4088,40 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4072
4088
4073
4089
if (WARN_ON_ONCE (h1_hdrs_sz < 0 ))
4074
4090
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 ))
4076
4094
return r ;
4077
4095
4078
4096
/* First line. */
4079
4097
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
+
4083
4113
if (auth )
4084
4114
__h2_msg_hdr_val (& ht -> tbl [TFW_HTTP_HDR_H2_AUTHORITY ], & host_val );
4085
4115
else if (host )
4086
4116
__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 ;
4089
4125
4090
4126
/* Skip host header: it's already written. */
4091
4127
FOR_EACH_HDR_FIELD_FROM (field , end , req , TFW_HTTP_HDR_REGULAR ) {
@@ -4096,19 +4132,25 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4096
4132
case TFW_HTTP_HDR_HOST :
4097
4133
continue ; /* Already written. */
4098
4134
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 ;
4100
4138
continue ;
4101
4139
case TFW_HTTP_HDR_CONTENT_TYPE :
4102
4140
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 ;
4104
4144
continue ;
4105
4145
}
4106
4146
break ;
4107
4147
case TFW_HTTP_HDR_COOKIE :
4108
4148
if (!TFW_STR_DUP (field ))
4109
4149
break ;
4110
- r | = write_merged_cookie_headers (
4150
+ r = write_merged_cookie_headers (
4111
4151
& ht -> tbl [TFW_HTTP_HDR_COOKIE ], & it );
4152
+ if (unlikely (r ))
4153
+ goto err ;
4112
4154
continue ;
4113
4155
default :
4114
4156
break ;
@@ -4131,20 +4173,33 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4131
4173
hval .nchunks ++ ;
4132
4174
hval .len += chunk -> len ;
4133
4175
}
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
+
4136
4183
hval .chunks += hval .nchunks ;
4137
4184
hval .nchunks = dup -> nchunks - hval .nchunks ;
4138
4185
hval .len = dup -> len - hval .len ;
4139
- r |= tfw_msg_write (& it , & hval );
4140
4186
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 ;
4142
4194
}
4143
4195
if (unlikely (r ))
4144
4196
goto err ;
4145
4197
}
4146
4198
4147
- r |= tfw_msg_write (& it , & h_via );
4199
+ r = tfw_msg_write (& it , & h_via );
4200
+ if (unlikely (r ))
4201
+ goto err ;
4202
+
4148
4203
if (need_cl ) {
4149
4204
h_cl = (TfwStr ) {
4150
4205
.chunks = (TfwStr []) {
@@ -4156,11 +4211,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4156
4211
.len = cl_len ,
4157
4212
.nchunks = 4
4158
4213
};
4159
- r |= tfw_msg_write (& it , & h_cl );
4214
+ r = tfw_msg_write (& it , & h_cl );
4215
+ if (unlikely (r ))
4216
+ goto err ;
4160
4217
}
4161
4218
/* Finally close headers. */
4162
- r |= tfw_msg_write (& it , & crlf );
4163
-
4219
+ r = tfw_msg_write (& it , & crlf );
4164
4220
if (unlikely (r ))
4165
4221
goto err ;
4166
4222
@@ -4208,11 +4264,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4208
4264
}
4209
4265
4210
4266
return 0 ;
4267
+
4211
4268
err :
4212
4269
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 ;
4216
4273
}
4217
4274
4218
4275
/*
0 commit comments