TS-1923: Fix resolve_logfield_string()

When bytes_resolved is 0, we should free result directly,
or it will return the not-null result to the caller with
the strlen(result) is 0, which will lead to ATS crash.

Signed-off-by: Yunkai Zhang <[email protected]>
Signed-off-by: Zhao Yongming <[email protected]>

Conflicts:
        CHANGES

test/review: igalic, sorber, zwoop
backport: igalic


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

Branch: refs/heads/3.2.x
Commit: 9f8195f443e1e16862cbb7abc0497ec64dafd025
Parents: 71bbb07
Author: Yunkai Zhang <[email protected]>
Authored: Sat May 25 00:49:04 2013 +0800
Committer: Igor Galić <[email protected]>
Committed: Fri Jun 14 15:31:46 2013 +0200

----------------------------------------------------------------------
 CHANGES                    | 5 +++--
 STATUS                     | 5 -----
 proxy/logging/LogAccess.cc | 7 ++++++-
 3 files changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9f8195f4/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index b844bdb..267b595 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 3.2.5
 
-  *) [TS-1918] SSL hangs after origin handshake.
+  *) [TS-1923] Fix memory issue caused by resolve_logfield_string()
+    Author: Yunkai Zhang <[email protected]>
 
-  *) [TS-1779] Crash when using ssl_ca_name
+  *) [TS-1918] SSL hangs after origin handshake.
 
   *) [TS-1483] Manager uses hardcoded FD limit causing restarts
    forever on traffic_server.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9f8195f4/STATUS
----------------------------------------------------------------------
diff --git a/STATUS b/STATUS
index ced70b7..5af3390 100644
--- a/STATUS
+++ b/STATUS
@@ -42,11 +42,6 @@ A list of all bugs open for the next development release can 
be found at
 
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
 
-  Fix crash in resolve_logfield_string()
-  Jira: https://issues.apache.org/jira/browse/TS-1923
-  Patches: a729aa63fcc7e7b5dcb8a19427067a8a20d4ed74
-  +1: igalic, sorber, zwoop
-
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9f8195f4/proxy/logging/LogAccess.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc
index 44c0cfa..649b31d 100644
--- a/proxy/logging/LogAccess.cc
+++ b/proxy/logging/LogAccess.cc
@@ -1418,7 +1418,12 @@ resolve_logfield_string(LogAccess *context, const char 
*format_str)
                                                             8191, 
LogUtils::timestamp(), 0,
                                                             
LOG_SEGMENT_VERSION);
   ink_assert(bytes_resolved < 8192);
-  result[bytes_resolved] = 0; // NULL terminate
+
+  if (!bytes_resolved) {
+    ats_free(result);
+    result = NULL;
+  } else
+    result[bytes_resolved] = 0; // NULL terminate
 
   ats_free(printf_str);
   ats_free(fields_str);

Reply via email to