ut/lvol: remove use of sprintf()

sprintf() has no bounds checks, and in this case it is actually
overwriting a buffer allocated with spdk_sprintf_alloc(), which isn't
guaranteed to be big enough for the name we want to place in it.

Rather than trying to rewrite the name in place, just free the old one
and allocate a new one.

Change-Id: Ia6ea17c2f0c8e4ed4995946356b8a09ba2a02cbf
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/382507
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-10-13 14:22:24 -07:00 committed by Jim Harris
parent 9760edb041
commit 08eeefc718

View File

@ -469,7 +469,9 @@ ut_lvol_resize(void)
CU_ASSERT(rc != 0); CU_ASSERT(rc != 0);
/* Resize with correct bdev name, but wrong lvol name */ /* Resize with correct bdev name, but wrong lvol name */
sprintf(g_lvol->name, "wrong name"); free(g_lvol->name);
g_lvol->name = strdup("wrong name");
SPDK_CU_ASSERT_FATAL(g_lvol->name != NULL);
rc = vbdev_lvol_resize(g_base_bdev->name, 20, vbdev_lvol_resize_complete, NULL); rc = vbdev_lvol_resize(g_base_bdev->name, 20, vbdev_lvol_resize_complete, NULL);
CU_ASSERT(rc != 0); CU_ASSERT(rc != 0);