diff mbox series

Use unsigned constants for ICMP6 filters [BZ #22489]

Message ID xn1rocbm9h.fsf@greed.delorie.com
State New
Headers show
Series Use unsigned constants for ICMP6 filters [BZ #22489] | expand

Commit Message

DJ Delorie April 24, 2020, 9:35 p.m. UTC
https://sourceware.org/bugzilla/show_bug.cgi?id=22489

The patch in the bz applies and builds without change.  I added my
analysis of the failure (newer gcc's give a much more useful message
;) although it's pretty obvious in retrospect.

Only four lines changed, well under the assignment threshold.

From: Sergey <s.korolev@ndmsystems.com>
Date: Fri, 24 Apr 2020 17:18:41 -0400
Subject: Use unsigned constants for ICMP6 filters [BZ #22489]

The core problem here is that the bitfields are unsigned but
the computed constants are signed.  This patch forces the computed
constants to be unsigned. - DJ

Comments

Andreas Schwab April 25, 2020, 8:53 a.m. UTC | #1
On Apr 24 2020, DJ Delorie via Libc-alpha wrote:

> The core problem here is that the bitfields are unsigned but
> the computed constants are signed.  This patch forces the computed
> constants to be unsigned. - DJ

That explanation doesn't make sense.  This has nothing to do with
signedness of bitfields, it is about shifting a value out of its range.

Andreas.
Florian Weimer April 26, 2020, 8:03 a.m. UTC | #2
* DJ Delorie via Libc-alpha:

> From: Sergey <s.korolev@ndmsystems.com>
> Date: Fri, 24 Apr 2020 17:18:41 -0400
> Subject: Use unsigned constants for ICMP6 filters [BZ #22489]
>
> The core problem here is that the bitfields are unsigned but
> the computed constants are signed.  This patch forces the computed
> constants to be unsigned. - DJ

I suggest to write “the icmp6_filt array elements are unsigned”
instead of “the bitfields are unsigned”.
diff mbox series

Patch

diff --git a/inet/netinet/icmp6.h b/inet/netinet/icmp6.h
index a75722887d..5fed0fbca1 100644
--- a/inet/netinet/icmp6.h
+++ b/inet/netinet/icmp6.h
@@ -85,16 +85,16 @@  struct icmp6_hdr
 #define ICMP6_PARAMPROB_OPTION        2 /* unrecognized IPv6 option */
 
 #define ICMP6_FILTER_WILLPASS(type, filterp) \
-	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
+	((((filterp)->icmp6_filt[(type) >> 5]) & (1U << ((type) & 31))) == 0)
 
 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
-	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
+	((((filterp)->icmp6_filt[(type) >> 5]) & (1U << ((type) & 31))) != 0)
 
 #define ICMP6_FILTER_SETPASS(type, filterp) \
-	((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
+	((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1U << ((type) & 31))))
 
 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
-	((((filterp)->icmp6_filt[(type) >> 5]) |=  (1 << ((type) & 31))))
+	((((filterp)->icmp6_filt[(type) >> 5]) |=  (1U << ((type) & 31))))
 
 #define ICMP6_FILTER_SETPASSALL(filterp) \
 	memset (filterp, 0, sizeof (struct icmp6_filter));