virtio: check socket path snprintf() return code
Fixes a GCC 7 warning: rte_virtio/virtio_user/vhost_user.c: In function ‘vhost_user_setup’: rte_virtio/virtio_user/vhost_user.c:439:46: error: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 108 [-Werror=format-truncation=] snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path); Change-Id: I147c9efe93cc6ce9370da6443f181f916457e3e6 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/375198 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
c2175d2c51
commit
59f2a376a3
@ -423,6 +423,7 @@ vhost_user_setup(struct virtio_user_dev *dev)
|
||||
int fd;
|
||||
int flag;
|
||||
struct sockaddr_un un;
|
||||
ssize_t rc;
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
@ -436,7 +437,12 @@ vhost_user_setup(struct virtio_user_dev *dev)
|
||||
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
|
||||
rc = snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
|
||||
if (rc < 0 || (size_t)rc >= sizeof(un.sun_path)) {
|
||||
PMD_DRV_LOG(ERR, "socket path too long");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
|
||||
PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
|
||||
close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user