hotspot/src/share/vm/prims/jvm.cpp
changeset 27471 6e56277909f1
parent 27405 ea143278766c
child 27612 7201412afbd0
--- a/hotspot/src/share/vm/prims/jvm.cpp	Mon Nov 03 11:34:13 2014 -0800
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Wed Oct 29 10:13:24 2014 +0100
@@ -2583,7 +2583,14 @@
 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
   // see bug 4399518, 4417214
   if ((intptr_t)count <= 0) return -1;
-  return vsnprintf(str, count, fmt, args);
+
+  int result = vsnprintf(str, count, fmt, args);
+  if ((result > 0 && (size_t)result >= count) || result == -1) {
+    str[count - 1] = '\0';
+    result = -1;
+  }
+
+  return result;
 }
 
 ATTRIBUTE_PRINTF(3, 0)