From 8e9b4b312bc6b164d6f50461f37a70a3826a31d3 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Thu, 22 Aug 2019 17:48:39 +0200 Subject: [PATCH] [#851,!24-p] Address issue in use of strcpy. --- src/lib/dhcp/tests/iface_mgr_unittest.cc | 2 +- src/lib/dhcpsrv/mysql_host_data_source.cc | 2 +- src/lib/testutils/unix_control_client.cc | 4 ++-- src/lib/util/io/socketsession.cc | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index 2a63a1a6a2..e372c758b9 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -2602,7 +2602,7 @@ checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) { struct ifreq ifr; memset(& ifr.ifr_name, 0, sizeof ifr.ifr_name); - strncpy(ifr.ifr_name, iface.getName().c_str(), sizeof ifr.ifr_name); + strncpy(ifr.ifr_name, iface.getName().c_str(), sizeof(ifr.ifr_name) - 1); int s = -1; // Socket descriptor diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index e577b4ac32..7963213e79 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -370,7 +370,7 @@ public: // auth key bind_[13].buffer_type = MYSQL_TYPE_STRING; std::string auth_key = host->getKey().toText(); - std::strncpy(auth_key_, auth_key.c_str(), TEXT_AUTH_KEY_LEN); + std::strncpy(auth_key_, auth_key.c_str(), TEXT_AUTH_KEY_LEN - 1); auth_key_null_ = auth_key.empty() ? MLM_TRUE : MLM_FALSE; bind_[13].buffer = auth_key_; bind_[13].buffer_length = auth_key.length(); diff --git a/src/lib/testutils/unix_control_client.cc b/src/lib/testutils/unix_control_client.cc index 2d180c85f0..f0f8dfaaab 100644 --- a/src/lib/testutils/unix_control_client.cc +++ b/src/lib/testutils/unix_control_client.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -56,7 +56,7 @@ bool UnixControlClient::connectToServer(const std::string& socket_path) { memset(&srv_addr, 0, sizeof(srv_addr)); srv_addr.sun_family = AF_UNIX; strncpy(srv_addr.sun_path, socket_path.c_str(), - sizeof(srv_addr.sun_path)); + sizeof(srv_addr.sun_path) - 1); socklen_t len = sizeof(srv_addr); // Connect to the specified UNIX socket diff --git a/src/lib/util/io/socketsession.cc b/src/lib/util/io/socketsession.cc index 5b3a72bd62..c19ab450f1 100644 --- a/src/lib/util/io/socketsession.cc +++ b/src/lib/util/io/socketsession.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -103,7 +103,7 @@ SocketSessionForwarder::SocketSessionForwarder(const std::string& unix_file) : // paranoid about making it 100% sure even if the check has a bug (with // triggering the assertion in the worse case) strncpy(impl.sock_un_.sun_path, unix_file.c_str(), - sizeof(impl.sock_un_.sun_path)); + sizeof(impl.sock_un_.sun_path) - 1); assert(impl.sock_un_.sun_path[sizeof(impl.sock_un_.sun_path) - 1] == '\0'); impl.sock_un_len_ = offsetof(struct sockaddr_un, sun_path) + unix_file.length(); -- 2.47.2