Repository: trafficserver
Updated Branches:
  refs/heads/master e564ec9b9 -> 1b57f42af


TS-2236: remove trailing null in response body set by fabricate_with_old_api

I'm seeing this too whenever a remap plugin set an error response
body using TSHttpTxnErrorBodySet.  I think the bug is simply failed
to realise that ink_bvsprintf will return resulting len including
the final null.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/1b57f42a
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/1b57f42a
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/1b57f42a

Branch: refs/heads/master
Commit: 1b57f42af928f76da298c97ea24a2b50dab58bc3
Parents: e564ec9
Author: Thach Tran <[email protected]>
Authored: Thu Jun 5 22:13:45 2014 +0700
Committer: James Peach <[email protected]>
Committed: Thu Jun 5 10:20:42 2014 -0700

----------------------------------------------------------------------
 CHANGES                       | 3 +++
 proxy/http/HttpBodyFactory.cc | 8 +++++---
 2 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1b57f42a/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 5a2ea66..9d67d29 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.1.0
 
+  *) [TS-2236] Remove trailing null in response body set by 
fabricate_with_old_api.
+   Author: Thach Tran <[email protected]>
+
   *) [TS-2877] http_load waits until timeout when response body is zero.
    Author: Masaori Koshiba <[email protected]>
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1b57f42a/proxy/http/HttpBodyFactory.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpBodyFactory.cc b/proxy/http/HttpBodyFactory.cc
index ee248a7..839c476 100644
--- a/proxy/http/HttpBodyFactory.cc
+++ b/proxy/http/HttpBodyFactory.cc
@@ -123,10 +123,12 @@ HttpBodyFactory::fabricate_with_old_api(const char *type, 
HttpTransact::State *
   // check if we don't need to format body //
   ///////////////////////////////////////////
   if (format) {
+    // The length from ink_bvsprintf includes the trailing NUL, so adjust the 
final
+    // length accordingly.
     int l = ink_bvsprintf(NULL, format, ap);
-    if (l < max_buffer_length) {
-      buffer = (char *)ats_malloc(l + 1);
-      *resulting_buffer_length = ink_bvsprintf(buffer, format, ap);
+    if (l <= max_buffer_length) {
+      buffer = (char *)ats_malloc(l);
+      *resulting_buffer_length = ink_bvsprintf(buffer, format, ap) - 1;
       plain_flag = true;
     }
   }

Reply via email to