# HG changeset patch # User clanger # Date 1521124703 -3600 # Node ID f654b37c58a1970a1548c47831c0190e586f66d9 # Parent e88237c5ac832832f7b2997b2dbc97eff9c23797 8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans Reviewed-by: stuefe, dholmes, cjplummer diff -r e88237c5ac83 -r f654b37c58a1 src/hotspot/share/services/attachListener.hpp --- 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/ostream.hpp" +#include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" -#include "utilities/globalDefinitions.hpp" +#include "utilities/ostream.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'; } }