]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: add safety check on ATTR_FLAG_BIT
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 7 Sep 2017 12:54:42 +0000 (14:54 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Thu, 7 Sep 2017 12:54:42 +0000 (14:54 +0200)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_attr.h

index 4dd38459f81742dc3f32b69f3886d937abd7ab09..ea1e736520046baa3440dfca7720f6df5a8dce9f 100644 (file)
@@ -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))                 \