Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/ifconfig Correct Undefined Behavior in ifconfig(8)



details:   https://anonhg.NetBSD.org/src/rev/8602df74e4de
branches:  trunk
changeset: 319784:8602df74e4de
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Jun 11 17:45:50 2018 +0000

description:
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>

diffstat:

 sbin/ifconfig/af_inet.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 342acba9983a -r 8602df74e4de sbin/ifconfig/af_inet.c
--- a/sbin/ifconfig/af_inet.c   Mon Jun 11 15:29:33 2018 +0000
+++ b/sbin/ifconfig/af_inet.c   Mon Jun 11 17:45:50 2018 +0000
@@ -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 @@
 
        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 */
        }
 



Home | Main Index | Thread Index | Old Index