]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Use unsigned constants for ICMP6 filters [BZ #22489]
authorSergey <s.korolev@ndmsystems.com>
Fri, 24 Apr 2020 21:18:41 +0000 (17:18 -0400)
committerDJ Delorie <dj@redhat.com>
Mon, 11 May 2020 21:09:05 +0000 (17:09 -0400)
The core problem here is that the filter array elements are unsigned
but the computed constants are signed.  This both causes a
signededness conversion at the &= step and may cause undefined
behavior if the MSB is being modified.  This patch uses unsigned
constants to avoid both cases. - DJ

inet/netinet/icmp6.h

index a75722887daf1399afc84dc1c74ae167dbeb16a6..5fed0fbca18be3010261d906fcd3d9494a056516 100644 (file)
@@ -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));