Skip to contentSkip to conversation

Segementation fault running qemu-img commit

Qemu-devel Ryan Rempel 1 participant 1 message Mar 29, 2005

lore
Share & tools
lore
#0 lore raw

I was getting a segmentation fault when running "qemu-img commit" (to commit changes back to the underlying filesystem).

It appears that the problem is that there is code in block-cow.c that "reads ahead" in a bitmap without checking whether it is falling off the end of the bitmap. At least in my case (running on FreeBSD 5) this ends up causing a segmentation fault.

I've attached a patch which appears to fix the problem (I'm not sure if it is the most elegant fix). I've tried to avoid an "off-by-one" problem in the patch, but you should probably review it to make sure I've got the logic right.

block-cow.c renamed from block-cow.c.orig +7 -0
@@ -162,6 +162,9 @@
                             int nb_sectors, int *pnum)
 {
     BDRVCowState *s = bs->opaque;
+    if (s->cow_bitmap_size <= (sector_num + nb_sectors) / 8) {
+        nb_sectors = (((int64_t) s->cow_bitmap_size) * 8) - sector_num; 
+    }
     return is_changed(s->cow_bitmap, sector_num, nb_sectors, pnum);
 }
 
@@ -170,6 +173,10 @@
 {
     BDRVCowState *s = bs->opaque;
     int ret, n;
+
+    if (s->cow_bitmap_size <= (sector_num + nb_sectors) / 8) {
+        nb_sectors = (((int64_t) s->cow_bitmap_size) * 8) - sector_num; 
+    }
     
     while (nb_sectors > 0) {
         if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) {