summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAyush Ujjwal <77244483+aujjwal-redhat@users.noreply.github.com>2021-03-22 15:37:20 +0530
committerGitHub <noreply@github.com>2021-03-22 15:37:20 +0530
commitcbdd7dc11189187e3a8191ed35de47b4715e6e21 (patch)
tree65174fea85e7c97abf5519bd81c0142ac5db6ee5
parentec189a499d85c2aad1d54e55e47df6b95ba02922 (diff)
downloadglusterfs-cbdd7dc11189187e3a8191ed35de47b4715e6e21.tar.gz
glusterfs-cbdd7dc11189187e3a8191ed35de47b4715e6e21.tar.xz
glusterfs-cbdd7dc11189187e3a8191ed35de47b4715e6e21.zip
CID 1412333 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW) (#2264)
* CID 1412333 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW) CID: 1412333 Description: `path` length might overrun the 108-character fixed-size string. Added a condition to check the size of `path`. Updates: #1060 Change-Id: I4e7c58ab3a3f6807992dfc3023c21f762bff6b32 Signed-off-by: aujjwal-redhat <aujjwal@redhat.com> * refactored the code Change-Id: I1eaa6fc59e43f76224f44b5f8c54495b67076651 Signed-off-by: aujjwal-redhat <aujjwal@redhat.com> * added strncpy in place of strcpy to store only the number of characters as much is size of addr-sunppath Change-Id: I9b4eeed3dd0c00d052dcaaf6b34597fbfe7fe1a2 Signed-off-by: aujjwal-redhat <aujjwal@redhat.com> * Removed goto err as it was already going to err Change-Id: Ib40c11537b57aea72d3095eda86bd5b541930550 Signed-off-by: aujjwal-redhat <aujjwal@redhat.com>
-rw-r--r--rpc/rpc-transport/socket/src/name.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c
index 9286bbb236..eefbaf0336 100644
--- a/rpc/rpc-transport/socket/src/name.c
+++ b/rpc/rpc-transport/socket/src/name.c
@@ -116,13 +116,16 @@ af_unix_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr,
}
addr = (struct sockaddr_un *)sockaddr;
- strcpy(addr->sun_path, path);
+
+ strncpy(addr->sun_path, path, sizeof(addr->sun_path));
+ addr->sun_path[sizeof(addr->sun_path) - 1] = '\0';
+
ret = bind(sock, (struct sockaddr *)addr, sockaddr_len);
+
if (ret == -1) {
gf_log(this->name, GF_LOG_ERROR,
"cannot bind to unix-domain socket %d (%s)", sock,
strerror(errno));
- goto err;
}
} else {
gf_log(this->name, GF_LOG_TRACE,