From 0006082054f43672b447efd90460ebaeea647815 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 4 Jun 2020 16:24:13 +0000 Subject: [PATCH] dhclient: Fix a logic bug remove_protocol(). A logic bug in remove_protocol() meant that it would remove (leak) all structures in the list preceding the one intended for removal. PR: 245971 Submitted by: joost@jodocus.org (original version) MFC after: 1 week --- sbin/dhclient/dispatch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 834dbd31c3f7..91f1694ec902 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -474,13 +474,16 @@ add_protocol(const char *name, int fd, void (*handler)(struct protocol *), void remove_protocol(struct protocol *proto) { - struct protocol *p, *next; + struct protocol *p, *prev; - for (p = protocols; p; p = next) { - next = p->next; + for (p = protocols, prev = NULL; p != NULL; prev = p, p = p->next) { if (p == proto) { - protocols = p->next; + if (prev == NULL) + protocols = p->next; + else + prev->next = p->next; free(p); + break; } } }