From 96099b4030d374cf1d34b3a6f3fa0e2dc1ed7a99 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 7 Sep 2017 14:54:42 +0200 Subject: [PATCH] bgpd: add safety check on ATTR_FLAG_BIT Signed-off-by: David Lamparter --- bgpd/bgp_attr.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)) \ -- 2.39.5