qmp: Add error proofing for query-acpi-ospm-status
PATCH 1/1 qmp: Add error proofing for query-acpi-ospm-status
The ACPI device may not implement the ospm_status callback. Executing qmp "query-acpi-ospm-status" will cause segmentation fault. Add error proofing add log to avoid such serious consequences.
Signed-off-by Kunkun Jiang <[email protected]>
--- monitor/qmp-cmds.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
monitor/qmp-cmds.c +6 -1
@@ -229,7 +229,12 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (obj);AcpiDeviceIf *adev =ACPI_DEVICE_IF (obj); - adevc->ospm_status (adev, &prev); +if (adevc->ospm_status) { + adevc->ospm_status (adev, &prev); + }else { +error_setg (errp,"command is not supported, " +"ACPI device missing ospm_status callback" ); + } }else {error_setg (errp,"command is not supported, missing ACPI device" ); }
Signature · 1 line
2.33.0