You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by cm...@apache.org on 2026/03/31 21:48:24 UTC

(trafficserver) 01/04: HttpSM - make sure we have a valid buffer to write on. (#13040)

This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch 10.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 732f7070d6d4b2712f6e7ac485c44778fdea1e54
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Mon Mar 30 16:05:57 2026 -0500

    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 d3ef5233aa07a0873c2f139ec4222f86e2ab89c1)
---
 src/proxy/http/HttpSM.cc                           |  5 +--
 .../post/simple-post-valid-buffer-check.test.py    | 51 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc
index b40fb8ef74..ccd687bf80 100644
--- a/src/proxy/http/HttpSM.cc
+++ b/src/proxy/http/HttpSM.cc
@@ -3061,7 +3061,6 @@ HttpSM::tunnel_handler_100_continue(int event, void *data)
     //  does not free the memory from the header
     t_state.hdr_info.client_response.destroy();
     tunnel.deallocate_buffers();
-    this->postbuf_clear();
     tunnel.reset();
 
     if (server_entry->eos) {
@@ -6403,8 +6402,8 @@ HttpSM::do_setup_client_request_body_tunnel(HttpVC_t to_vc_type)
   // YTS Team, yamsat Plugin
   // if redirect_in_process and redirection is enabled add static producer
 
-  if (is_buffering_request_body ||
-      (t_state.redirect_info.redirect_in_process && enable_redirection && this->_postbuf.postdata_copy_buffer_start != nullptr)) {
+  if ((is_buffering_request_body && this->_postbuf.is_valid()) || // Make sure  we have a valid buffer in case is buffering.
+      (t_state.redirect_info.redirect_in_process && enable_redirection && this->_postbuf.is_valid())) {
     post_redirect = true;
     // copy the post data into a new producer buffer for static producer
     MIOBuffer      *postdata_producer_buffer = new_empty_MIOBuffer(t_state.http_config_param->max_payload_iobuf_index);
diff --git a/tests/gold_tests/post/simple-post-valid-buffer-check.test.py b/tests/gold_tests/post/simple-post-valid-buffer-check.test.py
new file mode 100644
index 0000000000..600a36d6b2
--- /dev/null
+++ b/tests/gold_tests/post/simple-post-valid-buffer-check.test.py
@@ -0,0 +1,51 @@
+'''
+'''
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import os
+
+Test.Summary = '''
+Make sure we have a valid buffer to write on. This used to make ats crash.
+'''
+Test.ContinueOnFail = True
+
+server = Test.MakeHttpBinServer("server")
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.remap_config.AddLine('map / http://127.0.0.1:{0}'.format(server.Variables.Port))
+
+ts.Disk.records_config.update(
+    '''
+diags:
+    debug:
+        enabled: 1
+        tags: http
+http:
+    request_buffer_enabled: 1
+    number_of_redirections: 1
+
+''')
+
+test_run = Test.AddTestRun("post buffer test")
+test_run.Processes.Default.StartBefore(server)
+test_run.Processes.Default.StartBefore(ts)
+test_run.MakeCurlCommand(f' -v -H "Expect: 100-continue" -d "abc" http://localhost:{ts.Variables.port}/post', ts=ts)
+ts.Disk.traffic_out.Content += Testers.ContainsExpression("HTTP/1.1 100 Continue", "Has Expect header")
+ts.Disk.traffic_out.Content += Testers.ContainsExpression("HTTP/1.1 200 OK", "200OK")
+test_run.StillRunningAfter = server
+test_run.StillRunningAfter = ts  # TS should not crash
+test_run.Processes.Default.ReturnCode = 0