Commit 59f2a376 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/375198


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent c2175d2c
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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);