Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet6 Paper over Undefined Behavior in in6_control1()



details:   https://anonhg.NetBSD.org/src/rev/67a764ed8419
branches:  trunk
changeset: 833626:67a764ed8419
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 04 00:35:33 2018 +0000

description:
Paper over Undefined Behavior in in6_control1()

Replace calculation of maxexpire (TIME_MAX) with a construct that triggers
UB with a one that uses implementation defined semantics.

No functional change intended.

An attempt to appease KUBSAn.

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>

diffstat:

 sys/netinet6/in6.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (36 lines):

diff -r f9af6d81429b -r 67a764ed8419 sys/netinet6/in6.c
--- a/sys/netinet6/in6.c        Tue Jul 03 23:14:57 2018 +0000
+++ b/sys/netinet6/in6.c        Wed Jul 04 00:35:33 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6.c,v 1.268 2018/05/29 09:10:39 prlw1 Exp $  */
+/*     $NetBSD: in6.c,v 1.269 2018/07/04 00:35:33 kamil Exp $  */
 /*     $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $   */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.268 2018/05/29 09:10:39 prlw1 Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.269 2018/07/04 00:35:33 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -632,7 +632,7 @@
                         * signed.
                         */
                        maxexpire = ((time_t)~0) &
-                           ~((time_t)1 << ((sizeof(maxexpire) * NBBY) - 1));
+                           (time_t)~(1ULL << ((sizeof(maxexpire) * NBBY) - 1));
                        if (ia->ia6_lifetime.ia6t_vltime <
                            maxexpire - ia->ia6_updatetime) {
                                retlt->ia6t_expire = ia->ia6_updatetime +
@@ -653,7 +653,7 @@
                         * signed.
                         */
                        maxexpire = ((time_t)~0) &
-                           ~((time_t)1 << ((sizeof(maxexpire) * NBBY) - 1));
+                           (time_t)~(1ULL << ((sizeof(maxexpire) * NBBY) - 1));
                        if (ia->ia6_lifetime.ia6t_pltime <
                            maxexpire - ia->ia6_updatetime) {
                                retlt->ia6t_preferred = ia->ia6_updatetime +



Home | Main Index | Thread Index | Old Index