changeset 49411:f654b37c58a1

8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans Reviewed-by: stuefe, dholmes, cjplummer
author clanger
date Thu, 15 Mar 2018 15:38:23 +0100
parents e88237c5ac83
children 7fa5375fa6fd
files src/hotspot/share/services/attachListener.hpp
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/services/attachListener.hpp	Thu Mar 15 07:43:07 2018 +0100
+++ b/src/hotspot/share/services/attachListener.hpp	Thu Mar 15 15:38:23 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,9 +27,9 @@
 
 #include "memory/allocation.hpp"
 #include "utilities/debug.hpp"
+#include "utilities/globalDefinitions.hpp"
+#include "utilities/macros.hpp"
 #include "utilities/ostream.hpp"
-#include "utilities/macros.hpp"
-#include "utilities/globalDefinitions.hpp"
 
 // The AttachListener thread services a queue of operations that are enqueued
 // by client tools. Each operation is identified by a name and has up to 3
@@ -122,9 +122,10 @@
 
   // set the operation name
   void set_name(char* name) {
-    size_t len = strlen(name);
-    assert(len <= name_length_max, "exceeds maximum name length");
-    memcpy(_name, name, MIN2(len + 1, (size_t)name_length_max));
+    assert(strlen(name) <= name_length_max, "exceeds maximum name length");
+    size_t len = MIN2(strlen(name), (size_t)name_length_max);
+    memcpy(_name, name, len);
+    _name[len] = '\0';
   }
 
   // get an argument value
@@ -139,9 +140,10 @@
     if (arg == NULL) {
       _arg[i][0] = '\0';
     } else {
-      size_t len = strlen(arg);
-      assert(len <= arg_length_max, "exceeds maximum argument length");
-      memcpy(_arg[i], arg, MIN2(len + 1, (size_t)arg_length_max));
+      assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
+      size_t len = MIN2(strlen(arg), (size_t)arg_length_max);
+      memcpy(_arg[i], arg, len);
+      _arg[i][len] = '\0';
     }
   }