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>
This commit is contained in:
sri-mohan1 2022-07-27 12:14:46 +05:30
parent 594936dd0a
commit ac62d9fdca
1 changed files with 6 additions and 6 deletions

View File

@ -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;