Skip to content

Commit cb9e4a1

Browse files
bneradtbrbzull0
andauthored
HttpSM - make sure we have a valid buffer to write on. (#13039)
Add a check to make sure we have a valid buffer for tunnel producer to write on. Co-authored-by: Damian Meden <dmeden@apache.org>
1 parent e5accd7 commit cb9e4a1

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

proxy/http/HttpSM.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,6 @@ HttpSM::tunnel_handler_100_continue(int event, void *data)
29722972
// does not free the memory from the header
29732973
t_state.hdr_info.client_response.destroy();
29742974
tunnel.deallocate_buffers();
2975-
this->postbuf_clear();
29762975
tunnel.reset();
29772976

29782977
if (server_entry->eos) {
@@ -6103,8 +6102,8 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type)
61036102
// YTS Team, yamsat Plugin
61046103
// if redirect_in_process and redirection is enabled add static producer
61056104

6106-
if (is_using_post_buffer ||
6107-
(t_state.redirect_info.redirect_in_process && enable_redirection && this->_postbuf.postdata_copy_buffer_start != nullptr)) {
6105+
if ((is_using_post_buffer && this->_postbuf.is_valid()) || // Make sure we have a valid buffer in case is buffering.
6106+
(t_state.redirect_info.redirect_in_process && enable_redirection && this->_postbuf.is_valid())) {
61086107
post_redirect = true;
61096108
// copy the post data into a new producer buffer for static producer
61106109
MIOBuffer *postdata_producer_buffer = new_empty_MIOBuffer(t_state.http_config_param->max_payload_iobuf_index);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
Test.Summary = '''
20+
Make sure we have a valid buffer to write on. This used to make ats crash.
21+
'''
22+
Test.ContinueOnFail = True
23+
24+
# Use microserver instead of httpbin
25+
server = Test.MakeOriginServer("server")
26+
27+
# Add a simple response for POST
28+
request_header = {"headers": "POST /post HTTP/1.1\r\nHost: *\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
29+
response_header = {
30+
"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 2\r\n\r\n",
31+
"timestamp": "1469733493.993",
32+
"body": "OK"
33+
}
34+
server.addResponse("sessionfile.log", request_header, response_header)
35+
36+
ts = Test.MakeATSProcess("ts")
37+
38+
ts.Disk.remap_config.AddLine('map / http://127.0.0.1:{0}'.format(server.Variables.Port))
39+
40+
ts.Disk.records_config.update(
41+
{
42+
'proxy.config.diags.debug.enabled': 1,
43+
'proxy.config.diags.debug.tags': 'http',
44+
'proxy.config.http.request_buffer_enabled': 1,
45+
'proxy.config.http.number_of_redirections': 1,
46+
})
47+
48+
test_run = Test.AddTestRun("post buffer test")
49+
test_run.Processes.Default.StartBefore(server)
50+
test_run.Processes.Default.StartBefore(ts)
51+
test_run.Processes.Default.Command = f'curl -v -H "Expect: 100-continue" -d "abc" http://127.0.0.1:{ts.Variables.port}/post'
52+
test_run.Processes.Default.ReturnCode = 0
53+
test_run.StillRunningAfter = server
54+
test_run.StillRunningAfter = ts # TS should not crash
55+
56+
# Verify request with Expect header was processed
57+
ts.Disk.traffic_out.Content += Testers.ContainsExpression("100-continue", "Has Expect header")
58+
# Verify ATS handled the POST request (no crash)
59+
ts.Disk.traffic_out.Content += Testers.ContainsExpression("client post", "POST tunnel started")

0 commit comments

Comments
 (0)