diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-02-22 08:47:21 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-02-22 08:47:21 +0000 |
commit | c10bd60d794344a10307c0fe1cc3f34462bc4890 (patch) | |
tree | e778d3b5f1937b4137d8a873aee45306eb91c5e1 /sys/net/route.c | |
parent | 07b47afd71dfaecad83358117dd697e6decde7bc (diff) |
Always reallocate a new memory chunk when changing the gateway of a
route entry.
This makes sure we pass the correct size to free(9).
Reproted by and ok dlg@
Diffstat (limited to 'sys/net/route.c')
-rw-r--r-- | sys/net/route.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index 8a5cbd62e93..30c8def301d 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.372 2018/02/20 12:43:03 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.373 2018/02/22 08:47:20 mpi Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -1004,11 +1004,14 @@ rt_setgate(struct rtentry *rt, struct sockaddr *gate, u_int rtableid) int glen = ROUNDUP(gate->sa_len); struct sockaddr *sa; - if (rt->rt_gateway == NULL || glen > ROUNDUP(rt->rt_gateway->sa_len)) { + if (rt->rt_gateway == NULL || glen != ROUNDUP(rt->rt_gateway->sa_len)) { sa = malloc(glen, M_RTABLE, M_NOWAIT); if (sa == NULL) return (ENOBUFS); - free(rt->rt_gateway, M_RTABLE, 0); + if (rt->rt_gateway != NULL) { + free(rt->rt_gateway, M_RTABLE, + ROUNDUP(rt->rt_gateway->sa_len)); + } rt->rt_gateway = sa; } memmove(rt->rt_gateway, gate, glen); |