From b508aaca27e9b94f6232f1882d64a12fc5f229d9 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Tue, 5 Sep 2023 21:20:02 -0400 Subject: [PATCH] Fix handle use after free --- sys/kern/handle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/kern/handle.c b/sys/kern/handle.c index 49a2d82..cad6fa4 100644 --- a/sys/kern/handle.c +++ b/sys/kern/handle.c @@ -33,12 +33,12 @@ void Handle_Destroy(Process *proc) { int i; - Handle *handle; + Handle *handle, *handle_tmp; for (i = 0; i < PROCESS_HANDLE_SLOTS; i++) { - TAILQ_FOREACH(handle, &proc->handles[i], handleList) { - (handle->close)(handle); + TAILQ_FOREACH_SAFE(handle, &proc->handles[i], handleList, handle_tmp) { TAILQ_REMOVE(&proc->handles[i], handle, handleList); + (handle->close)(handle); } } }