@@ -3373,9 +3373,14 @@ __tfw_http_add_hdr_via(TfwHttpMsg *hm, int http_version, bool from_cache)
3373
3373
TfwStr crlf = { .data = S_CRLF , .len = SLEN (S_CRLF ) };
3374
3374
3375
3375
r = tfw_http_msg_expand_data (& mit -> iter , skb_head , & rh , NULL );
3376
- r |= tfw_http_msg_expand_data (& mit -> iter , skb_head ,
3376
+ if (unlikely (r ))
3377
+ goto finish ;
3378
+
3379
+ r = tfw_http_msg_expand_data (& mit -> iter , skb_head ,
3377
3380
& crlf , NULL );
3378
3381
}
3382
+
3383
+ finish :
3379
3384
if (r )
3380
3385
T_ERR ("Unable to add via: header to msg [%p]\n" , hm );
3381
3386
else
@@ -3558,13 +3563,17 @@ tfw_h1_set_loc_hdrs(TfwHttpMsg *hm, bool is_resp, bool from_cache)
3558
3563
/* h_mdf->eolen is ignored, add explicit CRLF. */
3559
3564
r = tfw_http_msg_expand_data (& mit -> iter , skb_head ,
3560
3565
& h_mdf , NULL );
3561
- r |= tfw_http_msg_expand_data (& mit -> iter , skb_head ,
3566
+ if (unlikely (r ))
3567
+ goto finish ;
3568
+
3569
+ r = tfw_http_msg_expand_data (& mit -> iter , skb_head ,
3562
3570
& crlf , NULL );
3563
3571
} else {
3564
3572
r = tfw_http_msg_hdr_xfrm_str (hm , & h_mdf , d -> hid ,
3565
3573
d -> append );
3566
3574
}
3567
3575
3576
+ finish :
3568
3577
if (r ) {
3569
3578
T_ERR ("can't update location-specific header in msg %p\n" ,
3570
3579
hm );
@@ -3912,11 +3921,18 @@ write_merged_cookie_headers(TfwStr *hdr, TfwMsgIter *it)
3912
3921
hval .nchunks -- ;
3913
3922
hval .len -= chunk -> len ;
3914
3923
}
3915
- r |= tfw_msg_write (it , cookie_dlm );
3916
- r |= tfw_msg_write (it , & hval );
3924
+ r = tfw_msg_write (it , cookie_dlm );
3925
+ if (unlikely (r ))
3926
+ return r ;
3927
+
3928
+ r = tfw_msg_write (it , & hval );
3929
+ if (unlikely (r ))
3930
+ return r ;
3931
+
3917
3932
cookie_dlm = & val_dlm ;
3918
3933
}
3919
- return r | tfw_msg_write (it , & crlf );
3934
+
3935
+ return tfw_msg_write (it , & crlf );
3920
3936
}
3921
3937
3922
3938
static int
@@ -4123,20 +4139,40 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4123
4139
4124
4140
if (WARN_ON_ONCE (h1_hdrs_sz < 0 ))
4125
4141
return - EINVAL ;
4126
- if ((r = tfw_msg_iter_setup (& it , & new_head , h1_hdrs_sz , 0 )))
4142
+
4143
+ r = tfw_msg_iter_setup (& it , & new_head , h1_hdrs_sz , 0 );
4144
+ if (unlikely (r ))
4127
4145
return r ;
4128
4146
4129
4147
/* First line. */
4130
4148
r = __h2_write_method (req , & it );
4131
- r |= tfw_msg_write (& it , & sp );
4132
- r |= tfw_msg_write (& it , & req -> uri_path );
4133
- r |= tfw_msg_write (& it , & fl_end ); /* start of Host: header */
4149
+ if (unlikely (r ))
4150
+ goto err ;
4151
+
4152
+ r = tfw_msg_write (& it , & sp );
4153
+ if (unlikely (r ))
4154
+ goto err ;
4155
+
4156
+ r = tfw_msg_write (& it , & req -> uri_path );
4157
+ if (unlikely (r ))
4158
+ goto err ;
4159
+
4160
+ r = tfw_msg_write (& it , & fl_end ); /* start of Host: header */
4161
+ if (unlikely (r ))
4162
+ goto err ;
4163
+
4134
4164
if (auth )
4135
4165
__h2_msg_hdr_val (& ht -> tbl [TFW_HTTP_HDR_H2_AUTHORITY ], & host_val );
4136
4166
else if (host )
4137
4167
__h2_msg_hdr_val (& ht -> tbl [TFW_HTTP_HDR_HOST ], & host_val );
4138
- r |= tfw_msg_write (& it , & host_val );
4139
- r |= tfw_msg_write (& it , & crlf );
4168
+
4169
+ r = tfw_msg_write (& it , & host_val );
4170
+ if (unlikely (r ))
4171
+ goto err ;
4172
+
4173
+ r = tfw_msg_write (& it , & crlf );
4174
+ if (unlikely (r ))
4175
+ goto err ;
4140
4176
4141
4177
/* Skip host header: it's already written. */
4142
4178
FOR_EACH_HDR_FIELD_FROM (field , end , req , TFW_HTTP_HDR_REGULAR ) {
@@ -4147,19 +4183,25 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4147
4183
case TFW_HTTP_HDR_HOST :
4148
4184
continue ; /* Already written. */
4149
4185
case TFW_HTTP_HDR_X_FORWARDED_FOR :
4150
- r |= tfw_msg_write (& it , & h_xff );
4186
+ r = tfw_msg_write (& it , & h_xff );
4187
+ if (unlikely (r ))
4188
+ goto err ;
4151
4189
continue ;
4152
4190
case TFW_HTTP_HDR_CONTENT_TYPE :
4153
4191
if (h_ct_replace ) {
4154
- r |= tfw_msg_write (& it , & h_ct );
4192
+ r = tfw_msg_write (& it , & h_ct );
4193
+ if (unlikely (r ))
4194
+ goto err ;
4155
4195
continue ;
4156
4196
}
4157
4197
break ;
4158
4198
case TFW_HTTP_HDR_COOKIE :
4159
4199
if (!TFW_STR_DUP (field ))
4160
4200
break ;
4161
- r | = write_merged_cookie_headers (
4201
+ r = write_merged_cookie_headers (
4162
4202
& ht -> tbl [TFW_HTTP_HDR_COOKIE ], & it );
4203
+ if (unlikely (r ))
4204
+ goto err ;
4163
4205
continue ;
4164
4206
default :
4165
4207
break ;
@@ -4182,20 +4224,33 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4182
4224
hval .nchunks ++ ;
4183
4225
hval .len += chunk -> len ;
4184
4226
}
4185
- r |= tfw_msg_write (& it , & hval );
4186
- r |= tfw_msg_write (& it , & dlm );
4227
+ r = tfw_msg_write (& it , & hval );
4228
+ if (unlikely (r ))
4229
+ goto err ;
4230
+ r = tfw_msg_write (& it , & dlm );
4231
+ if (unlikely (r ))
4232
+ goto err ;
4233
+
4187
4234
hval .chunks += hval .nchunks ;
4188
4235
hval .nchunks = dup -> nchunks - hval .nchunks ;
4189
4236
hval .len = dup -> len - hval .len ;
4190
- r |= tfw_msg_write (& it , & hval );
4191
4237
4192
- r |= tfw_msg_write (& it , & crlf );
4238
+ r = tfw_msg_write (& it , & hval );
4239
+ if (unlikely (r ))
4240
+ goto err ;
4241
+
4242
+ r = tfw_msg_write (& it , & crlf );
4243
+ if (unlikely (r ))
4244
+ goto err ;
4193
4245
}
4194
4246
if (unlikely (r ))
4195
4247
goto err ;
4196
4248
}
4197
4249
4198
- r |= tfw_msg_write (& it , & h_via );
4250
+ r = tfw_msg_write (& it , & h_via );
4251
+ if (unlikely (r ))
4252
+ goto err ;
4253
+
4199
4254
if (need_cl ) {
4200
4255
h_cl = (TfwStr ) {
4201
4256
.chunks = (TfwStr []) {
@@ -4207,11 +4262,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4207
4262
.len = cl_len ,
4208
4263
.nchunks = 4
4209
4264
};
4210
- r |= tfw_msg_write (& it , & h_cl );
4265
+ r = tfw_msg_write (& it , & h_cl );
4266
+ if (unlikely (r ))
4267
+ goto err ;
4211
4268
}
4212
4269
/* Finally close headers. */
4213
- r |= tfw_msg_write (& it , & crlf );
4214
-
4270
+ r = tfw_msg_write (& it , & crlf );
4215
4271
if (unlikely (r ))
4216
4272
goto err ;
4217
4273
@@ -4259,11 +4315,12 @@ tfw_h2_adjust_req(TfwHttpReq *req)
4259
4315
}
4260
4316
4261
4317
return 0 ;
4318
+
4262
4319
err :
4263
4320
ss_skb_queue_purge (& new_head );
4264
- T_DBG3 ("%s: req [%p ] convertation to http1.1 has failed\n" ,
4265
- __func__ , req );
4266
- return - EINVAL ;
4321
+ T_DBG3 ("%s: req [%px ] convertation to http1.1 has failed"
4322
+ " with result (%d)\n" , __func__ , req , r );
4323
+ return r ;
4267
4324
}
4268
4325
4269
4326
/*
0 commit comments