]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
OSPF: variable-length array of size 0 replaced by alloca()'d pointer
authorMaria Matejka <mq@ucw.cz>
Fri, 16 Aug 2019 10:47:13 +0000 (12:47 +0200)
committerMaria Matejka <mq@ucw.cz>
Sat, 17 Aug 2019 11:49:10 +0000 (13:49 +0200)
NULL pointer is safer than a random pointer onto stack if this function
gets changed and eventually broken.

proto/ospf/ospf.c

index 643b50543de81553d2aabafc411fb0b0641dffc7..b580ad32937b734c62b88d073cea962e4a73713a 100644 (file)
@@ -1289,7 +1289,7 @@ ospf_sh_state(struct proto *P, int verbose, int reachable)
 
   uint num = p->gr->hash_entries;
   struct top_hash_entry *hea[num];
-  struct top_hash_entry *hex[verbose ? num : 0];
+  struct top_hash_entry **hex = verbose ? alloca(num * sizeof(struct top_hash_entry *)) : NULL;
   struct top_hash_entry *he;
   struct top_hash_entry *cnode = NULL;
 
@@ -1334,7 +1334,9 @@ ospf_sh_state(struct proto *P, int verbose, int reachable)
 
   lsa_compare_ospf3 = !ospf2;
   qsort(hea, j1, sizeof(struct top_hash_entry *), lsa_compare_for_state);
-  qsort(hex, jx, sizeof(struct top_hash_entry *), ext_compare_for_state);
+
+  if (verbose)
+    qsort(hex, jx, sizeof(struct top_hash_entry *), ext_compare_for_state);
 
   /*
    * This code is a bit tricky, we have a primary LSAs (router and