[PATCH] isa-superio: validate floppy.count value

Paolo Bonzini posted 1 patch 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240129133249.1105704-1-pbonzini@redhat.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
hw/isa/isa-superio.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] isa-superio: validate floppy.count value
Posted by Paolo Bonzini 10 months ago
Ensure that the value is valid; it can only be zero or one.
And never create a floppy disk controller if it is zero.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/isa/isa-superio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c
index 80e0c34652e..34df335598c 100644
--- a/hw/isa/isa-superio.c
+++ b/hw/isa/isa-superio.c
@@ -116,7 +116,9 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
     }
 
     /* Floppy disc */
-    if (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0)) {
+    assert(k->floppy.count <= 1);
+    if (k->floppy.count &&
+        (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0))) {
         isa = isa_new(TYPE_ISA_FDC);
         d = DEVICE(isa);
         if (k->floppy.get_iobase) {
-- 
2.43.0
Re: [PATCH] isa-superio: validate floppy.count value
Posted by Philippe Mathieu-Daudé 10 months ago
On 29/1/24 14:32, Paolo Bonzini wrote:
> Ensure that the value is valid; it can only be zero or one.
> And never create a floppy disk controller if it is zero.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   hw/isa/isa-superio.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>