Skip to content

Commit

Permalink
Fix invalid strncpy destination buffer size
Browse files Browse the repository at this point in the history
`strncpy` function does not guaranty the zero-byte at the end of a destination
buffer in case of source string truncation so the limit should be less
that the destination size.

Relates #169
  • Loading branch information
GeorgyKirichenko authored and GeorgyKirichenko committed Apr 15, 2024
1 parent 499e193 commit 13a2ca0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autotest/autotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ eResult tAutotest::initSockets()
}
struct sockaddr_un sockaddr;
sockaddr.sun_family = AF_UNIX;
strncpy(sockaddr.sun_path, pci.data() + strlen(SOCK_DEV_PREFIX), sizeof(sockaddr.sun_path));
strncpy(sockaddr.sun_path, pci.data() + strlen(SOCK_DEV_PREFIX), sizeof(sockaddr.sun_path) - 1);
if (connect(fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) < 0)
{
YANET_LOG_ERROR("error: could not connect: %s\n", strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion dataplane/sock_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ int sock_dev_create(const char* name, uint8_t numa_node)
unlink(path);
internals->fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
internals->sockaddr.sun_family = AF_UNIX;
strncpy(internals->sockaddr.sun_path, path, sizeof(internals->sockaddr.sun_path));
strncpy(internals->sockaddr.sun_path, path, sizeof(internals->sockaddr.sun_path) - 1);
bind(internals->fd, (struct sockaddr*)&internals->sockaddr, sizeof(internals->sockaddr));
listen(internals->fd, 1);
internals->conFd = -1;
Expand Down

0 comments on commit 13a2ca0

Please sign in to comment.