From: David Lamparter Date: Thu, 7 Sep 2017 12:54:42 +0000 (+0200) Subject: bgpd: add safety check on ATTR_FLAG_BIT X-Git-Tag: frr-4.0-dev~327^2~5 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=96099b4030d374cf1d34b3a6f3fa0e2dc1ed7a99;p=matthieu%2Ffrr.git bgpd: add safety check on ATTR_FLAG_BIT Signed-off-by: David Lamparter --- diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 4dd38459f8..ea1e736520 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -207,7 +207,12 @@ struct transit { u_char *val; }; -#define ATTR_FLAG_BIT(X) (1ULL << ((X) - 1)) +/* "(void) 0" will generate a compiler error. this is a safety check to + * ensure we're not using a value that exceeds the bit size of attr->flag. */ +#define ATTR_FLAG_BIT(X) \ + __builtin_choose_expr((X) >= 1 && (X) <= 64, \ + 1ULL << ((X) - 1), \ + (void) 0) #define BGP_CLUSTER_LIST_LENGTH(attr) \ (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \