Selaa lähdekoodia

vhost: fix infinite loop on error path

file.index is unsigned, hence 'while (--file.index >= 0)'
will loop > forever. Change to while (file.index-- > 0).

Reported-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Michael S. Tsirkin 15 vuotta sitten
vanhempi
commit
6b37c87c96
1 muutettua tiedostoa jossa 1 lisäystä ja 1 poistoa
  1. 1 1
      hw/vhost_net.c

+ 1 - 1
hw/vhost_net.c

@@ -151,7 +151,7 @@ int vhost_net_start(struct vhost_net *net,
     return 0;
     return 0;
 fail:
 fail:
     file.fd = -1;
     file.fd = -1;
-    while (--file.index >= 0) {
+    while (file.index-- > 0) {
         int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);
         int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);
         assert(r >= 0);
         assert(r >= 0);
     }
     }