Fix deregistration of a callback that is not at the head of the list.

The SLIST_FOREACH_PREVPTR macro doesn't work the way I thought it did.
Just store our own prev pointer and use that instead.
This commit is contained in:
Todd C. Miller
2020-12-30 07:09:35 -07:00
parent 4151d8fc80
commit 9547755c3f

View File

@@ -278,18 +278,19 @@ sudo_fatal_callback_register_v1(sudo_fatal_callback_t func)
int
sudo_fatal_callback_deregister_v1(sudo_fatal_callback_t func)
{
struct sudo_fatal_callback *cb, **prev;
struct sudo_fatal_callback *cb, *prev = NULL;
/* Search for callback and remove if found, dupes are not allowed. */
SLIST_FOREACH_PREVPTR(cb, prev, &callbacks, entries) {
SLIST_FOREACH(cb, &callbacks, entries) {
if (cb->func == func) {
if (cb == SLIST_FIRST(&callbacks))
if (prev == NULL)
SLIST_REMOVE_HEAD(&callbacks, entries);
else
SLIST_REMOVE_AFTER(*prev, entries);
SLIST_REMOVE_AFTER(prev, entries);
free(cb);
return 0;
}
prev = cb;
}
return -1;