From 0692768e69d35545bbe47cc0a47cda70ef61dcc7 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 18 Apr 2018 15:50:50 -0700 Subject: [PATCH] vhost: Fix negative array index use in spdk_vhost_set_socket_path If basename was the string "", with length 0, it would have resulted in accessing index -1 in dev_dirname. Change-Id: Ib389f8fe220f5335a54f6a155a20fcca35b94e3e Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/408253 Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System --- lib/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index e639e7d5d..08f3ad813 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1128,6 +1128,9 @@ spdk_vhost_set_socket_path(const char *basename) if (basename && strlen(basename) > 0) { ret = snprintf(dev_dirname, sizeof(dev_dirname) - 2, "%s", basename); + if (ret <= 0) { + return -EINVAL; + } if ((size_t)ret >= sizeof(dev_dirname) - 2) { SPDK_ERRLOG("Char dev dir path length %d is too long\n", ret); return -EINVAL;