hw/cxl/events: Fix handling of component ID in event records generation to not assume it is a string
Fix handling of component ID in event records generation to not assume it is a string. Component ID in CXL events is 16 bytes data, but event record generation copy 15 bytes only from the qmp "component-id" field using strncpy. Replace strncpy with memcpy and copy the entire component ID data. Fixes: ea9b6d647f2f("hw/cxl/events: Add injection of General Media Events") Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Shiju Jose <shiju.jose@huawei.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260306101423.986-4-shiju.jose@huawei.com>
Shiju Jose committed
Mar 6, 2026 at 10:14 UTC
bae67e770aab251a9604ef8b81c67e6fe877baa3
1 file changed
+3
-6
hw/mem/cxl_type3.c
+3
-6
@@ -1895,8 +1895,7 @@ void qmp_cxl_inject_general_media_event(const char *path, CxlEventLog log,
1895
}
1896
1897
if (component_id) {
1898
- strncpy((char *)gem.component_id, component_id,
1899
- sizeof(gem.component_id) - 1);
1898
+ memcpy(gem.component_id, component_id, sizeof(gem.component_id));
1899
valid_flags |= CXL_GMER_VALID_COMPONENT;
1900
if (has_comp_id_pldm && is_comp_id_pldm) {
1901
valid_flags |= CXL_GMER_VALID_COMPONENT_ID_FORMAT;
@@ -2066,8 +2065,7 @@ void qmp_cxl_inject_dram_event(const char *path, CxlEventLog log,
2065
}
2066
2067
if (component_id) {
2069
- strncpy((char *)dram.component_id, component_id,
2070
- sizeof(dram.component_id) - 1);
2068
+ memcpy(dram.component_id, component_id, sizeof(dram.component_id));
2069
valid_flags |= CXL_DRAM_VALID_COMPONENT;
2070
if (has_comp_id_pldm && is_comp_id_pldm) {
2071
valid_flags |= CXL_DRAM_VALID_COMPONENT_ID_FORMAT;
@@ -2185,8 +2183,7 @@ void qmp_cxl_inject_memory_module_event(const char *path, CxlEventLog log,
2183
corrected_persist_error_count);
2184
2185
if (component_id) {
2188
- strncpy((char *)module.component_id, component_id,
2189
- sizeof(module.component_id) - 1);
2186
+ memcpy(module.component_id, component_id, sizeof(module.component_id));
2187
valid_flags |= CXL_MMER_VALID_COMPONENT;
2188
if (has_comp_id_pldm && is_comp_id_pldm) {
2189
valid_flags |= CXL_MMER_VALID_COMPONENT_ID_FORMAT;