From: sri-mohan1 Date: Wed, 27 Jul 2022 06:44:46 +0000 (+0530) Subject: ospfclient: condition optimization X-Git-Tag: base_8.4~185^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ac62d9fdca5a891dc575a13ae8ee8c19b0535b92;p=matthieu%2Ffrr.git ospfclient: condition optimization Its better to check the length and then the type of the LSA Signed-off-by: sri-mohan1 --- diff --git a/ospfclient/ospf_apiclient.c b/ospfclient/ospf_apiclient.c index 41f0b25b91..b5e6389d4c 100644 --- a/ospfclient/ospf_apiclient.c +++ b/ospfclient/ospf_apiclient.c @@ -439,6 +439,12 @@ int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient, struct lsa_header *lsah; uint32_t tmp; + /* Validate opaque LSA length */ + if ((size_t)opaquelen > sizeof(buf) - sizeof(struct lsa_header)) { + fprintf(stderr, "opaquelen(%d) is larger than buf size %zu\n", + opaquelen, sizeof(buf)); + return OSPF_API_NOMEMORY; + } /* We can only originate opaque LSAs */ if (!IS_OPAQUE_LSA(lsa_type)) { @@ -447,12 +453,6 @@ int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient, return OSPF_API_ILLEGALLSATYPE; } - if ((size_t)opaquelen > sizeof(buf) - sizeof(struct lsa_header)) { - fprintf(stderr, "opaquelen(%d) is larger than buf size %zu\n", - opaquelen, sizeof(buf)); - return OSPF_API_NOMEMORY; - } - /* Make a new LSA from parameters */ lsah = (struct lsa_header *)buf; lsah->ls_age = 0;