scsi: fix allocation for s390x loadparm
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 19 Nov 2024 21:31:22 +0000 (22:31 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 20 Nov 2024 00:29:29 +0000 (01:29 +0100)
Coverity reports a possible buffer overrun due to a non-NUL-terminated
string in scsi_property_set_loadparm().  While things are not so easy,
because qdev_prop_sanitize_s390x_loadparm is designed to operate on a
buffer that is not NUL-terminated, in this case the string *does* have
to be NUL-terminated because it is read by scsi_property_get_loadparm
and s390_build_iplb.

Reviewed-by: jrossi@linux.ibm.com
Cc: thuth@redhat.com
Fixes: 429442e52d9 ("hw: Add "loadparm" property to scsi disk devices for booting on s390x", 2024-11-18)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi/scsi-disk.c

index 8e553487d50efb47c852439ab3618c07915567e4..7f13b0588f249349dbfb3d5e0fc01931588c881a 100644 (file)
@@ -3152,7 +3152,7 @@ static void scsi_property_set_loadparm(Object *obj, const char *value,
         return;
     }
 
-    lp_str = g_malloc0(strlen(value));
+    lp_str = g_malloc0(strlen(value) + 1);
     if (!qdev_prop_sanitize_s390x_loadparm(lp_str, value, errp)) {
         g_free(lp_str);
         return;