From: Sangwan Kwon Date: Fri, 10 Jan 2020 04:32:33 +0000 (+0900) Subject: Fix stringop-truncation warning X-Git-Tag: submit/tizen/20200110.050843~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2ff0d1c0ed3be3ed9441077ee9416a4ddffc11d;p=platform%2Fcore%2Fsecurity%2Fklay.git Fix stringop-truncation warning Pathname sockets: The pathname in sun_path should be null-terminated. ref: http://man7.org/linux/man-pages/man7/unix.7.html Change-Id: I5d2f64639a598d9d5c991e928a4e43ab16d36088 Signed-off-by: Sangwan Kwon --- diff --git a/src/rmi/socket.cpp b/src/rmi/socket.cpp index 7370473..1950572 100644 --- a/src/rmi/socket.cpp +++ b/src/rmi/socket.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-present Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -252,7 +252,8 @@ int Socket::createRegularSocket(const std::string& path) ::sockaddr_un addr; addr.sun_family = AF_UNIX; - ::strncpy(addr.sun_path, path.c_str(), sizeof(sockaddr_un::sun_path)); + ::strncpy(addr.sun_path, path.c_str(), sizeof(sockaddr_un::sun_path) - 1); + addr.sun_path[sizeof(sockaddr_un::sun_path) - 1] = '\0'; if (addr.sun_path[0] == '@') { addr.sun_path[0] = '\0'; @@ -307,7 +308,8 @@ Socket Socket::connect(const std::string& path) sockaddr_un addr; addr.sun_family = AF_UNIX; - ::strncpy(addr.sun_path, path.c_str(), sizeof(sockaddr_un::sun_path)); + ::strncpy(addr.sun_path, path.c_str(), sizeof(sockaddr_un::sun_path) - 1); + addr.sun_path[sizeof(sockaddr_un::sun_path) - 1] = '\0'; if (addr.sun_path[0] == '@') { addr.sun_path[0] = '\0';