Skip to contentSkip to conversation

qemu: fix use after free

PATCH In review Jan Beulich 2 participants 2 messages Jan 14, 2011 – Jan 17, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu: fix use after free

Commit 99d53fbb69d3e03be61ae10506a304a3d08d792f introduced this, and the compiler indirectly warned about it.

The patch is only compile tested (I don't even know how to reproduce the original problem), but I suppose worth applying regardless.

keymaps.c +4 -7
@@ -56,15 +56,12 @@ typedef struct {
 
 static void del_key_range(struct key_range **krp, int code) {
     struct key_range *kr;
-    struct key_range *kr_pr;
-    for (kr = *krp; kr; kr_pr = kr, kr = kr->next) {
+    while ((kr = *krp) != NULL) {
         if (code >= kr->start && code <= kr->end) {
-            if (kr == *krp)
-                *krp = kr->next;
-            else
-                kr_pr->next = kr->next;
+            *krp = kr->next;
             qemu_free(kr);
-        }
+        } else
+            krp = &kr->next;
     }
 }
 

Commit 99d53fbb69d3e03be61ae10506a304a3d08d792f introduced this, and the compiler indirectly warned about it.

The patch is only compile tested (I don't even know how to reproduce the original problem), but I suppose worth applying regardless.

keymaps.c +4 -7
@@ -56,15 +56,12 @@ typedef struct {
 
 static void del_key_range(struct key_range **krp, int code) {
     struct key_range *kr;
-    struct key_range *kr_pr;
-    for (kr = *krp; kr; kr_pr = kr, kr = kr->next) {
+    while ((kr = *krp) != NULL) {
         if (code >= kr->start && code <= kr->end) {
-            if (kr == *krp)
-                *krp = kr->next;
-            else
-                kr_pr->next = kr->next;
+            *krp = kr->next;
             qemu_free(kr);
-        }
+        } else
+            krp = &kr->next;
     }
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Jan Beulich writes ("[Xen-devel] [PATCH] qemu: fix use after free"):

Quoted 5 lines

Commit 99d53fbb69d3e03be61ae10506a304a3d08d792f introduced this, and the compiler indirectly warned about it.

The patch is only compile tested (I don't even know how to reproduce the original problem), but I suppose worth applying regardless.

Well done for spotting this, I have applied your patch.

Ian.