Module Name: src Committed By: kamil Date: Mon Jun 11 17:45:51 UTC 2018
Modified Files: src/sbin/ifconfig: af_inet.c Log Message: Correct Undefined Behavior in ifconfig(8) Unportable left shift reported with MKSANITIZER=yes USE_SANITIZER=undefined: # ifconfig alc0: flags=0x8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ec_capabilities=3<VLAN_MTU,VLAN_HWTAGGING> ec_enabled=0 address: xx:xx:xx:xx:xx:xx /public/src.git/sbin/ifconfig/af_inet.c:102:34: runtime error: left shift of 16777215 by 8 places cannot be represented in type 'int' inet 192.168.0.38/24 broadcast 192.168.0.255 flags 0x0 inet6 xxxx::xxxx:xxxx:xxxx:xxx%alc0/64 flags 0x0 scopeid 0x1 lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33624 inet 127.0.0.1/8 flags 0x0 inet6 ::1/128 flags 0x20<NODAD> inet6 fe80::1%lo0/64 flags 0x0 scopeid 0x2 Change shifting left 1 to shifting 1U. This corrects the issue. if (cidr < 32) { /* more than 1 bit in mask */ /* check for non-contig netmask */ if ((mask ^ (((1 << cidr) - 1) << (32 - cidr))) != 0) // <- here return -1; /* noncontig, no pfxlen */ } Solution suggested by <uwe> Sponsored by <The NetBSD Foundation> To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/sbin/ifconfig/af_inet.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/ifconfig/af_inet.c diff -u src/sbin/ifconfig/af_inet.c:1.24 src/sbin/ifconfig/af_inet.c:1.25 --- src/sbin/ifconfig/af_inet.c:1.24 Sat Oct 1 20:59:49 2016 +++ src/sbin/ifconfig/af_inet.c Mon Jun 11 17:45:50 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: af_inet.c,v 1.24 2016/10/01 20:59:49 kre Exp $ */ +/* $NetBSD: af_inet.c,v 1.25 2018/06/11 17:45:50 kamil Exp $ */ /* * Copyright (c) 1983, 1993 @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: af_inet.c,v 1.24 2016/10/01 20:59:49 kre Exp $"); +__RCSID("$NetBSD: af_inet.c,v 1.25 2018/06/11 17:45:50 kamil Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -99,7 +99,7 @@ in_prefixlen(struct sockaddr *sa) if (cidr < 32) { /* more than 1 bit in mask */ /* check for non-contig netmask */ - if ((mask ^ (((1 << cidr) - 1) << (32 - cidr))) != 0) + if ((mask ^ (((1U << cidr) - 1) << (32 - cidr))) != 0) return -1; /* noncontig, no pfxlen */ }