Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospf6d: memcmp cleanup #10070

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ospf6d: replace memcmp with correct comparisons
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 16, 2021
commit 66314e9fe0cbd867fdfe3dd7b2fc71c2e7983454
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