spapr_events: use QTAILQ_FOREACH_SAFE() in spapr_clear_pending_events()
PATCH 1/1 spapr_events: use QTAILQ_FOREACH_SAFE() in spapr_clear_pending_events()
QTAILQ_FOREACH_SAFE() must be used when removing the current element inside the loop block.
This fixes a user-after-free error introduced by commit 56258174238eb and reported by Coverity (CID 1381017).
Signed-off-by Greg Kurz <[email protected]>
--- hw/ppc/spapr_events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/spapr_events.c +2 -2
@@ -702,9 +702,9 @@ static void event_scan(PowerPCCPU *cpu, sPAPRMachineState *spapr,void spapr_clear_pending_events (sPAPRMachineState *spapr) { -sPAPREventLogEntry *entry =NULL ; +sPAPREventLogEntry *entry =NULL , *next_entry; - QTAILQ_FOREACH(entry, &spapr->pending_events, next) { + QTAILQ_FOREACH_SAFE(entry, &spapr->pending_events, next, next_entry) {QTAILQ_REMOVE (&spapr->pending_events, entry, next);g_free (entry->extended_log);g_free (entry);
David Gibson
AppliedQuoted 7 lines · Greg Kurz
QTAILQ_FOREACH_SAFE()must be used when removing the current element inside the loop block.This fixes a user-after-free error introduced by commit
56258174238eband reported by Coverity (CID 1381017).Signed-off-by Greg Kurz <[email protected]>
Applied to ppc-for-2.11.
Quoted 21 lines
--- hw/ppc/spapr_events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/ppc/spapr_events.c +2
-2@@ -702,9 +702,9 @@ static void event_scan(PowerPCCPU *cpu, sPAPRMachineState *spapr,void spapr_clear_pending_events (sPAPRMachineState *spapr) { -sPAPREventLogEntry *entry =NULL ; +sPAPREventLogEntry *entry =NULL , *next_entry; - QTAILQ_FOREACH(entry, &spapr->pending_events, next) { + QTAILQ_FOREACH_SAFE(entry, &spapr->pending_events, next, next_entry) {QTAILQ_REMOVE (&spapr->pending_events, entry, next);g_free (entry->extended_log);g_free (entry);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson