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 <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/408253 Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
6518338fa0
commit
0692768e69
@ -1128,6 +1128,9 @@ spdk_vhost_set_socket_path(const char *basename)
|
|||||||
|
|
||||||
if (basename && strlen(basename) > 0) {
|
if (basename && strlen(basename) > 0) {
|
||||||
ret = snprintf(dev_dirname, sizeof(dev_dirname) - 2, "%s", basename);
|
ret = snprintf(dev_dirname, sizeof(dev_dirname) - 2, "%s", basename);
|
||||||
|
if (ret <= 0) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
if ((size_t)ret >= sizeof(dev_dirname) - 2) {
|
if ((size_t)ret >= sizeof(dev_dirname) - 2) {
|
||||||
SPDK_ERRLOG("Char dev dir path length %d is too long\n", ret);
|
SPDK_ERRLOG("Char dev dir path length %d is too long\n", ret);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
Loading…
Reference in New Issue
Block a user