]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfclient: condition optimization
authorsri-mohan1 <sri.mohan@samsung.com>
Wed, 27 Jul 2022 06:44:46 +0000 (12:14 +0530)
committersri-mohan1 <sri.mohan@samsung.com>
Wed, 27 Jul 2022 09:29:53 +0000 (14:59 +0530)
Its better to check the length and then the type of the LSA

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
ospfclient/ospf_apiclient.c

index 41f0b25b916c8cac18f476e79036be693f379fb0..b5e6389d4c9b0cee3690537ed72bafe56753a36e 100644 (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;