From c4a5da54af55556d57e139437c41d80ec44fa331 Mon Sep 17 00:00:00 2001 From: yasuoka Date: Thu, 30 Aug 2018 01:32:53 +0000 Subject: [PATCH] Fix "route add 0.0.0.0/0 " to work properly. Shift count beyonds the integer width results undefined behavior in C spec. Actually the count is masked by 0x1f on amd64. Found by asou at soum.co.jp ok claudio kn schwarze --- sbin/route/route.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 8f18e27b4e1..e255fd6ec6f 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.224 2018/08/09 19:48:44 schwarze Exp $ */ +/* $OpenBSD: route.c,v 1.225 2018/08/30 01:32:53 yasuoka Exp $ */ /* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* @@ -763,10 +763,14 @@ inet_makenetandmask(u_int32_t net, struct sockaddr_in *sin, int bits) char *cp; rtm_addrs |= RTA_NETMASK; - if (bits == 0 && net != 0) - bits = 32; - mask = 0xffffffff << (32 - bits); - net &= mask; + if (bits == 0 && net == 0) + mask = 0; + else { + if (bits == 0) + bits = 32; + mask = 0xffffffff << (32 - bits); + net &= mask; + } sin->sin_addr.s_addr = htonl(net); sin = &so_mask.sin; sin->sin_addr.s_addr = htonl(mask); -- 2.20.1