The overflow check for the relative metric adjustments of filtersets
assumes a certain overflow behaviour of signed integers. I think it is
better to write this in a way that does not involve an overflow.

OK?
-- 
:wq Claudio

Index: rde_filter.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v
retrieving revision 1.124
diff -u -p -r1.124 rde_filter.c
--- rde_filter.c        5 Nov 2020 11:51:13 -0000       1.124
+++ rde_filter.c        2 Dec 2020 11:12:24 -0000
@@ -48,8 +48,8 @@ rde_apply_set(struct filter_set_head *sh
                        break;
                case ACTION_SET_RELATIVE_LOCALPREF:
                        if (set->action.relative > 0) {
-                               if (set->action.relative + state->aspath.lpref <
-                                   state->aspath.lpref)
+                               if (state->aspath.lpref >=
+                                   UINT_MAX - set->action.relative)
                                        state->aspath.lpref = UINT_MAX;
                                else
                                        state->aspath.lpref +=
@@ -70,8 +70,8 @@ rde_apply_set(struct filter_set_head *sh
                case ACTION_SET_RELATIVE_MED:
                        state->aspath.flags |= F_ATTR_MED | F_ATTR_MED_ANNOUNCE;
                        if (set->action.relative > 0) {
-                               if (set->action.relative + state->aspath.med <
-                                   state->aspath.med)
+                               if (state->aspath.med >=
+                                   UINT_MAX - set->action.relative)
                                        state->aspath.med = UINT_MAX;
                                else
                                        state->aspath.med +=
@@ -90,8 +90,8 @@ rde_apply_set(struct filter_set_head *sh
                        break;
                case ACTION_SET_RELATIVE_WEIGHT:
                        if (set->action.relative > 0) {
-                               if (set->action.relative + state->aspath.weight
-                                   < state->aspath.weight)
+                               if (state->aspath.weight >=
+                                   UINT_MAX - set->action.relative)
                                        state->aspath.weight = UINT_MAX;
                                else
                                        state->aspath.weight +=

Reply via email to