Repository: trafficserver
Updated Branches:
  refs/heads/master 8dad69f7b -> 51ce5405d


Fix bug with _xstrdup where it incorrectly calls ink_strlcpy with zero length 
strings


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

Branch: refs/heads/master
Commit: 51ce5405d10e6a945f819ee3f05517d6a574e744
Parents: 8dad69f
Author: Brian Geffon <[email protected]>
Authored: Fri Nov 21 15:00:16 2014 -0800
Committer: Brian Geffon <[email protected]>
Committed: Fri Nov 21 15:00:16 2014 -0800

----------------------------------------------------------------------
 lib/ts/ink_memory.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/51ce5405/lib/ts/ink_memory.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_memory.cc b/lib/ts/ink_memory.cc
index 91aa403..764f71b 100644
--- a/lib/ts/ink_memory.cc
+++ b/lib/ts/ink_memory.cc
@@ -234,7 +234,12 @@ _xstrdup(const char *str, int length, const char* /* path 
ATS_UNUSED */)
       length = strlen(str);
 
     newstr = (char *)ats_malloc(length + 1);
-    ink_strlcpy(newstr, str, length + 1);
+    // If this is a zero length string just null terminate and return.
+    if (unlikely(length == 0)) {
+      *newstr = '\0';
+    } else {
+      ink_strlcpy(newstr, str, length + 1);
+    }
     return newstr;
   }
   return NULL;


Reply via email to