Skip to content

Commit c735ae7

Browse files
bneradtcmcfarlen
authored andcommitted
HttpSM - make sure we have a valid buffer to write on. (#13040)
Add a check to make sure we have a valid buffer for tunnel producer to write on. (cherry picked from commit d3ef523)
1 parent 7c2c689 commit c735ae7

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

src/proxy/http/HttpSM.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,7 +2979,6 @@ HttpSM::tunnel_handler_100_continue(int event, void *data)
29792979
// does not free the memory from the header
29802980
t_state.hdr_info.client_response.destroy();
29812981
tunnel.deallocate_buffers();
2982-
this->postbuf_clear();
29832982
tunnel.reset();
29842983

29852984
if (server_entry->eos) {
@@ -6315,8 +6314,8 @@ HttpSM::do_setup_client_request_body_tunnel(HttpVC_t to_vc_type)
63156314
// YTS Team, yamsat Plugin
63166315
// if redirect_in_process and redirection is enabled add static producer
63176316

6318-
if (is_buffering_request_body ||
6319-
(t_state.redirect_info.redirect_in_process && enable_redirection && this->_postbuf.postdata_copy_buffer_start != nullptr)) {
6317+
if ((is_buffering_request_body && this->_postbuf.is_valid()) || // Make sure we have a valid buffer in case is buffering.
6318+
(t_state.redirect_info.redirect_in_process && enable_redirection && this->_postbuf.is_valid())) {
63206319
post_redirect = true;
63216320
// copy the post data into a new producer buffer for static producer
63226321
MIOBuffer *postdata_producer_buffer = new_empty_MIOBuffer(t_state.http_config_param->max_payload_iobuf_index);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'''
2+
'''
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
import os
20+
21+
Test.Summary = '''
22+
Make sure we have a valid buffer to write on. This used to make ats crash.
23+
'''
24+
Test.ContinueOnFail = True
25+
26+
server = Test.MakeHttpBinServer("server")
27+
ts = Test.MakeATSProcess("ts")
28+
29+
ts.Disk.remap_config.AddLine('map / http://127.0.0.1:{0}'.format(server.Variables.Port))
30+
31+
ts.Disk.records_config.update(
32+
'''
33+
diags:
34+
debug:
35+
enabled: 1
36+
tags: http
37+
http:
38+
request_buffer_enabled: 1
39+
number_of_redirections: 1
40+
41+
''')
42+
43+
test_run = Test.AddTestRun("post buffer test")
44+
test_run.Processes.Default.StartBefore(server)
45+
test_run.Processes.Default.StartBefore(ts)
46+
test_run.MakeCurlCommand(f' -v -H "Expect: 100-continue" -d "abc" http://localhost:{ts.Variables.port}/post', ts=ts)
47+
ts.Disk.traffic_out.Content += Testers.ContainsExpression("HTTP/1.1 100 Continue", "Has Expect header")
48+
ts.Disk.traffic_out.Content += Testers.ContainsExpression("HTTP/1.1 200 OK", "200OK")
49+
test_run.StillRunningAfter = server
50+
test_run.StillRunningAfter = ts # TS should not crash
51+
test_run.Processes.Default.ReturnCode = 0

0 commit comments

Comments
 (0)