@samitouri / QOSamiQemu / commits / 91beb27a48

hw/cxl: Fix handling of component ID to not assume it is a string

Add following fixes, 1. Coverity reports a warning (CID 1645325) for use of strncpy() in handling of component ID. In cxl_create_mem_sparing_event_records(), fix handling of component ID to not assume it is a string by replacing strncpy with memcpy to solve this warning and copy the entire component ID data, which is 16 bytes. 2. In cxl_maintenance_insert(), - replace strncpy with memcpy to copy full data because component ID, which is 16 bytes data. - remove memset which is not required. Closes ("https://lore.kernel.org/qemu-devel/CAFEAcA_CsVe4TUVm3o_-BA4hXvi2xAThGX5T97amgTQKW_kiYA@mail.gmail.com/") Fixes: 5e5a86bab830("hw/cxl: Add support for Maintenance command and Post Package Repair (PPR)") Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Shiju Jose <shiju.jose@huawei.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260306101423.986-2-shiju.jose@huawei.com>

Shiju Jose committed Mar 6, 2026 at 10:14 UTC 91beb27a4851fe47fe68a5f715af5db456b9d37d
2 files changed +3 -5
hw/cxl/cxl-mailbox-utils.c
+2 -2
@@ -1994,8 +1994,8 @@ static void cxl_create_mem_sparing_event_records(CXLType3Dev *ct3d,
1994 stw_le_p(&event_rec.column, ent->column);
1995 event_rec.sub_channel = ent->sub_channel;
1996 if (ent->validity_flags & CXL_MSER_VALID_COMP_ID) {
1997 - strncpy((char *)event_rec.component_id, (char *)ent->component_id,
1998 - sizeof(event_rec.component_id));
1997 + memcpy(event_rec.component_id, ent->component_id,
1998 + sizeof(event_rec.component_id));
1999 }
2000 } else if (sparing_pi) {
2001 event_rec.flags = CXL_MSER_FLAGS_QUERY_RESOURCES;
hw/mem/cxl_type3.c
+1 -3
@@ -1767,7 +1767,6 @@ static void cxl_maintenance_insert(CXLType3Dev *ct3d, uint64_t dpa,
1767 }
1768 }
1769 m = g_new0(CXLMaintenance, 1);
1770 - memset(m, 0, sizeof(*m));
1770 m->dpa = dpa;
1771 m->validity_flags = 0;
1772
@@ -1804,8 +1803,7 @@ static void cxl_maintenance_insert(CXLType3Dev *ct3d, uint64_t dpa,
1803 m->validity_flags |= CXL_MSER_VALID_SUB_CHANNEL;
1804 }
1805 if (component_id) {
1807 - strncpy((char *)m->component_id, component_id,
1808 - sizeof(m->component_id) - 1);
1806 + memcpy(m->component_id, component_id, sizeof(m->component_id));
1807 m->validity_flags |= CXL_MSER_VALID_COMP_ID;
1808 if (has_comp_id_pldm && is_comp_id_pldm) {
1809 m->validity_flags |= CXL_MSER_VALID_COMP_ID_FORMAT;