libxl: fix use-after-free in discard_events iteration
authorMatthew Daley <mattjd@gmail.com>
Tue, 10 Sep 2013 14:34:17 +0000 (02:34 +1200)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 13 Sep 2013 12:14:37 +0000 (13:14 +0100)
We need to use the foreach variant which gets the next pointer before
the loop body is executed.

Coverity-ID: 1056193
Signed-off-by: Matthew Daley <mattjd@gmail.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl.c

index 7a7aaf90fe97acd24a4428a3077c21b7b3398fb1..0879f2331f39cb2dcdbf5a63686c08db87e69572 100644 (file)
@@ -122,8 +122,8 @@ static void free_disable_deaths(libxl__gc *gc,
 
 static void discard_events(struct libxl__event_list *l) {
     /* doesn't bother unlinking from the list, so l is corrupt on return */
-    libxl_event *ev;
-    LIBXL_TAILQ_FOREACH(ev, l, link)
+    libxl_event *ev, *next;
+    LIBXL_TAILQ_FOREACH_SAFE(ev, l, link, next)
         libxl_event_free(0, ev);
 }