Message ID | xn1rocbm9h.fsf@greed.delorie.com |
---|---|
State | New |
Headers | show |
Series | Use unsigned constants for ICMP6 filters [BZ #22489] | expand |
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.
* 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 --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));
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