Skip to content

Commit

Permalink
ospf6d: replace memcmp with correct comparisons
Browse files Browse the repository at this point in the history
Using memcmp with complex structures like prefix or ospf6_ls_origin is
not correct, because even two structures with same values in all fields
may have different values in padding bytes and comparison will fail.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
  • Loading branch information
idryzhov committed Nov 15, 2021
1 parent 8f359e1 commit 01d4fb7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ospf6d/ospf6_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,13 @@ extern const char *const ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
#define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
#define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"

#define ospf6_route_is_prefix(p, r) \
(memcmp(p, &(r)->prefix, sizeof(struct prefix)) == 0)
#define ospf6_route_is_prefix(p, r) (prefix_same(p, &(r)->prefix))
#define ospf6_route_is_same(ra, rb) (prefix_same(&(ra)->prefix, &(rb)->prefix))
#define ospf6_route_is_same_origin(ra, rb) \
((ra)->path.area_id == (rb)->path.area_id \
&& memcmp(&(ra)->path.origin, &(rb)->path.origin, \
sizeof(struct ospf6_ls_origin)) \
== 0)
&& (ra)->path.origin.type == (rb)->path.origin.type \
&& (ra)->path.origin.id == (rb)->path.origin.id \
&& (ra)->path.origin.adv_router == (rb)->path.origin.adv_router)

#define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))

Expand Down

0 comments on commit 01d4fb7

Please sign in to comment.