From ac62d9fdca5a891dc575a13ae8ee8c19b0535b92 Mon Sep 17 00:00:00 2001 From: sri-mohan1 Date: Wed, 27 Jul 2022 12:14:46 +0530 Subject: [PATCH] ospfclient: condition optimization Its better to check the length and then the type of the LSA Signed-off-by: sri-mohan1 --- ospfclient/ospf_apiclient.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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; -- 2.39.5