diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 48a7012ada..b06796ada0 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -705,7 +705,8 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, } start = (char *)link_lsa + sizeof(struct ospf6_link_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); + for (current = start; current < end; current += OSPF6_PREFIX_SIZE(prefix)) { prefix = (struct ospf6_prefix *)current; @@ -864,7 +865,7 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa, start = (char *)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); current = start; while (current + sizeof(struct ospf6_prefix) <= end) { @@ -935,7 +936,8 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, start = (char *)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); + for (current = start; current < end; current += OSPF6_PREFIX_SIZE(prefix)) { prefix = (struct ospf6_prefix *)current; @@ -1315,7 +1317,8 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread) prefix_num = (unsigned short)ntohl(link_lsa->prefix_num); start = (char *)link_lsa + sizeof(struct ospf6_link_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); + for (current = start; current < end && prefix_num; current += OSPF6_PREFIX_SIZE(op)) { op = (struct ospf6_prefix *)current; @@ -1770,7 +1773,7 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) prefix_num = ntohs(intra_prefix_lsa->prefix_num); start = (caddr_t)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = OSPF6_LSA_END(lsa->header); + end = ospf6_lsa_end(lsa->header); for (current = start; current < end; current += OSPF6_PREFIX_SIZE(op)) { op = (struct ospf6_prefix *)current; if (prefix_num == 0) @@ -1974,7 +1977,7 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) prefix_num = ntohs(intra_prefix_lsa->prefix_num); start = (caddr_t)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = OSPF6_LSA_END(lsa->header); + end = ospf6_lsa_end(lsa->header); for (current = start; current < end; current += OSPF6_PREFIX_SIZE(op)) { op = (struct ospf6_prefix *)current; if (prefix_num == 0) diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 24643164c5..b907ccbc20 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -66,7 +66,7 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, char *start, *end, *current; start = ospf6_lsa_header_end(lsa->header); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); if (use_json) { json_object_string_add(json_obj, "lsaType", "unknown"); @@ -548,7 +548,7 @@ void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa, json_object *json = NULL; start = (uint8_t *)lsa->header; - end = (uint8_t *)lsa->header + ntohs(lsa->header->length); + end = (uint8_t *)ospf6_lsa_end(lsa->header); if (use_json) { json = json_object_new_object(); diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 0fa632449f..714cd5883d 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -88,14 +88,17 @@ struct ospf6_lsa_header { }; #define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length)) -#define OSPF6_LSA_END(h) \ - ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length)) static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header) { return (char *)header + sizeof(struct ospf6_lsa_header); } +static inline char *ospf6_lsa_end(struct ospf6_lsa_header *header) +{ + return (char *)header + ntohs(header->length); +} + #define OSPF6_LSA_IS_TYPE(t, L) \ ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0) #define OSPF6_LSA_IS_SAME(L1, L2) \ diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 93120df999..7d6dcf8e36 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -207,7 +207,7 @@ static char *ospf6_lsdesc_backlink(struct ospf6_lsa *lsa, caddr_t lsdesc, ? sizeof(struct ospf6_router_lsdesc) : sizeof(struct ospf6_network_lsdesc)); for (backlink = ospf6_lsa_header_end(lsa->header) + 4; - backlink + size <= OSPF6_LSA_END(lsa->header); backlink += size) { + backlink + size <= ospf6_lsa_end(lsa->header); backlink += size) { assert(!(OSPF6_LSA_IS_TYPE(NETWORK, lsa) && VERTEX_IS_TYPE(NETWORK, v))); @@ -511,7 +511,7 @@ void ospf6_spf_calculation(uint32_t router_id, ? sizeof(struct ospf6_router_lsdesc) : sizeof(struct ospf6_network_lsdesc)); for (lsdesc = ospf6_lsa_header_end(v->lsa->header) + 4; - lsdesc + size <= OSPF6_LSA_END(v->lsa->header); + lsdesc + size <= ospf6_lsa_end(v->lsa->header); lsdesc += size) { lsa = ospf6_lsdesc_lsa(lsdesc, v); if (lsa == NULL)