aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-03-01 10:48:54 +0000
committerGitHub <noreply@github.com>2021-03-01 10:48:54 +0000
commit2d39c2cc5e5cb919821979771d2101a5f423ce14 (patch)
treee9677f2001d5a1dc4599957f471d1c0b660e8708 /test
parent442958cdabf03015f87e57a5183b9aa8ac815b06 (diff)
downloadlibvfio-user-2d39c2cc5e5cb919821979771d2101a5f423ce14.zip
libvfio-user-2d39c2cc5e5cb919821979771d2101a5f423ce14.tar.gz
libvfio-user-2d39c2cc5e5cb919821979771d2101a5f423ce14.tar.bz2
properly initialize capabilities in unit tests (#363)
Found via valgrind. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'test')
-rw-r--r--test/unit-tests.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/test/unit-tests.c b/test/unit-tests.c
index 2d39175..dd8ccc4 100644
--- a/test/unit-tests.c
+++ b/test/unit-tests.c
@@ -673,15 +673,15 @@ test_pci_caps(void **state UNUSED)
vsc2->hdr.id = PCI_CAP_ID_VNDR;
vsc2->size = 16;
- memcpy(vsc2->data, "Hello world.", 12);
+ memcpy(vsc2->data, "Hello world.", 13);
vsc3->hdr.id = PCI_CAP_ID_VNDR;
vsc3->size = 16;
- memcpy(vsc3->data, "Hello world.", 12);
+ memcpy(vsc3->data, "Hello world.", 13);
vsc4->hdr.id = PCI_CAP_ID_VNDR;
vsc4->size = 16;
- memcpy(vsc4->data, "Hello world.", 12);
+ memcpy(vsc4->data, "Hello world.", 13);
offset = vfu_pci_add_capability(&vfu_ctx, 0, VFU_CAP_FLAG_CALLBACK, &pm);
assert_int_equal(-1, offset);
@@ -835,11 +835,17 @@ test_pci_ext_caps(void **state UNUSED)
.reg_info = reg_info,
};
- struct pcie_ext_cap_vsc_hdr *vsc1 = alloca(sizeof(*vsc1) + 5);
- struct pcie_ext_cap_vsc_hdr *vsc2 = alloca(sizeof(*vsc2) + 13);
- struct pcie_ext_cap_vsc_hdr *vsc3 = alloca(sizeof(*vsc3) + 13);
- struct pcie_ext_cap_vsc_hdr *vsc4 = alloca(sizeof(*vsc4) + 13);
struct pcie_ext_cap_hdr *hdr;
+ size_t explens[] = {
+ sizeof(struct pcie_ext_cap_vsc_hdr) + 5,
+ sizeof(struct pcie_ext_cap_vsc_hdr) + 13,
+ sizeof(struct pcie_ext_cap_vsc_hdr) + 13,
+ sizeof(struct pcie_ext_cap_vsc_hdr) + 13,
+ };
+ struct pcie_ext_cap_vsc_hdr *vsc1 = alloca(explens[0]);
+ struct pcie_ext_cap_vsc_hdr *vsc2 = alloca(explens[1]);
+ struct pcie_ext_cap_vsc_hdr *vsc3 = alloca(explens[2]);
+ struct pcie_ext_cap_vsc_hdr *vsc4 = alloca(explens[3]);
size_t expoffsets[] = {
PCI_CFG_SPACE_SIZE,
PCI_CFG_SPACE_SIZE + sizeof(struct dsncap),
@@ -859,22 +865,31 @@ test_pci_ext_caps(void **state UNUSED)
vfu_ctx.reg_info[VFU_PCI_DEV_CFG_REGION_IDX].cb = test_pci_ext_caps_region_cb;
vfu_ctx.reg_info[VFU_PCI_DEV_CFG_REGION_IDX].size = PCI_CFG_SPACE_EXP_SIZE;
+ memset(&dsn, 0, sizeof (dsn));
+
dsn.hdr.id = PCI_EXT_CAP_ID_DSN;
dsn.sn_lo = 0x4;
dsn.sn_hi = 0x8;
+ memset(vsc1, 0, explens[0]);
+ vsc1->len = explens[0];
vsc1->hdr.id = PCI_EXT_CAP_ID_VNDR;
- vsc1->len = sizeof(*vsc1) + 5;
memcpy(vsc1->data, "abcde", 5);
+
+ memset(vsc2, 0, explens[1]);
+ vsc2->len = explens[1];
vsc2->hdr.id = PCI_EXT_CAP_ID_VNDR;
- vsc2->len = sizeof(*vsc2) + 13;
- memcpy(vsc2->data, "Hello world.", 12);
+ memcpy(vsc2->data, "Hello world.", 13);
+
+ memset(vsc3, 0, explens[2]);
+ vsc3->len = explens[2];
vsc3->hdr.id = PCI_EXT_CAP_ID_VNDR;
- vsc3->len = sizeof(*vsc3) + 13;
- memcpy(vsc3->data, "Hello world.", 12);
+ memcpy(vsc3->data, "Hello world.", 13);
+
+ memset(vsc4, 0, explens[3]);
+ vsc4->len = explens[3];
vsc4->hdr.id = PCI_EXT_CAP_ID_VNDR;
- vsc4->len = sizeof(*vsc4) + 13;
- memcpy(vsc4->data, "Hello world.", 12);
+ memcpy(vsc4->data, "Hello world.", 13);
offset = vfu_pci_add_capability(&vfu_ctx, 4096, VFU_CAP_FLAG_EXTENDED, &dsn);
assert_int_equal(-1, offset);