< prev index next >

src/hotspot/share/services/attachListener.hpp

Print this page
rev 49200 : 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -120,13 +120,14 @@
  public:
   const char* name() const                      { return _name; }
 
   // 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
   const char* arg(int i) const {
     assert(i>=0 && i<arg_count_max, "invalid argument index");

@@ -137,13 +138,14 @@
   void set_arg(int i, char* arg) {
     assert(i>=0 && i<arg_count_max, "invalid argument index");
     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';
     }
   }
 
   // create an operation of a given name
   AttachOperation(char* name) {
< prev index next >