summaryrefslogtreecommitdiff
path: root/ospfclient
diff options
context:
space:
mode:
authorsri-mohan1 <sri.mohan@samsung.com>2022-07-27 12:14:46 +0530
committersri-mohan1 <sri.mohan@samsung.com>2022-07-27 14:59:53 +0530
commitac62d9fdca5a891dc575a13ae8ee8c19b0535b92 (patch)
tree00558889683ae9b7310ad849dffd0a8624ba786e /ospfclient
parent594936dd0a77a07af0cedc68a1e35a835518840d (diff)
ospfclient: condition optimization
Its better to check the length and then the type of the LSA Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
Diffstat (limited to 'ospfclient')
-rw-r--r--ospfclient/ospf_apiclient.c12
1 files 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;