From d2084f835172ddcdd7edc962c98f9ee6e541fd5c Mon Sep 17 00:00:00 2001 From: mvs Date: Tue, 7 Sep 2021 16:07:46 +0000 Subject: [PATCH] Fix NULL pointer dereference introduced by previous commit. Reported-by: syzbot+684597dbbb9b516e76ae@syzkaller.appspotmail.com ok mpi@ --- sys/net/rtsock.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 8a8a74f5a51..7cdd8fe4881 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.320 2021/09/07 09:56:00 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.321 2021/09/07 16:07:46 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -1032,14 +1032,6 @@ rtm_output(struct rt_msghdr *rtm, struct rtentry **prt, rt = NULL; } - ifp = if_get(rt->rt_ifidx); - if (ifp == NULL) { - rtfree(rt); - rt = NULL; - error = ESRCH; - break; - } - /* * If RTAX_GATEWAY is the argument we're trying to * change, try to find a compatible route. @@ -1068,6 +1060,14 @@ rtm_output(struct rt_msghdr *rtm, struct rtentry **prt, break; } + ifp = if_get(rt->rt_ifidx); + if (ifp == NULL) { + rtfree(rt); + rt = NULL; + error = ESRCH; + break; + } + /* * RTM_CHANGE needs a perfect match. */ -- 2.20.1