Fix stringop-truncation warning 58/222158/2
authorSangwan Kwon <sangwan.kwon@samsung.com>
Fri, 10 Jan 2020 04:32:33 +0000 (13:32 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Fri, 10 Jan 2020 05:01:51 +0000 (14:01 +0900)
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 <sangwan.kwon@samsung.com>
src/rmi/socket.cpp

index 73704737f490ce3dcd45e2990f86e8eb523685ed..1950572d1a216e8f315d77f1dc6ada03729aa841 100644 (file)
@@ -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';