tech-kern archive

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

Undefined int shift in ifwatchd



I think my analysis here applies to this instance as well:

https://marc.info/?l=openbsd-tech&m=145377854103866&w=2

I also changed the chained condition to a switch statement because I
find that more readable.

Thanks for your time,
Michael


Index: ifwatchd.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/ifwatchd/ifwatchd.c,v
retrieving revision 1.26
diff -u -p -r1.26 ifwatchd.c
--- ifwatchd.c	30 Aug 2011 18:57:38 -0000	1.26
+++ ifwatchd.c	27 Jan 2016 17:34:12 -0000
@@ -292,7 +292,8 @@ check_addrs(char *cp, int addrs, enum ev
 	struct sockaddr *sa, *ifa = NULL, *brd = NULL;
 	char ifname_buf[IFNAMSIZ];
 	const char *ifname;
-	int ifndx = 0, i;
+	int ifndx = 0;
+	unsigned int i;
 
 	if (addrs == 0)
 		return;
@@ -300,7 +301,8 @@ check_addrs(char *cp, int addrs, enum ev
 		if ((i & addrs) == 0)
 			continue;
 		sa = (struct sockaddr *)cp;
-		if (i == RTA_IFP) {
+		switch (i) {
+		case RTA_IFP:
 			struct sockaddr_dl * li = (struct sockaddr_dl*)sa;
 			ifndx = li->sdl_index;
 			if (!find_interface(ifndx)) {
@@ -308,10 +310,16 @@ check_addrs(char *cp, int addrs, enum ev
 					printf("ignoring change on interface #%d\n", ifndx);
 				return;
 			}
-		} else if (i == RTA_IFA)
+			break;
+		case RTA_IFA:
 			ifa = sa;
-		else if (i == RTA_BRD)
+			break;
+		case RTA_BRD:
 			brd = sa;
+			break;
+		default:
+			break;
+		}
 		RT_ADVANCE(cp, sa);
 	}
 	if (ifa != NULL) {



Home | Main Index | Thread Index | Old Index