Skip to content

Commit

Permalink
ospfclient: Ensure ospf_apiclient_lsa_originate cannot accidently wri…
Browse files Browse the repository at this point in the history
…te into stack

Even though OSPF_MAX_LSA_SIZE is quite large and holds the upper bound
on what can be written into a lsa, let's add a small check to ensure
it is not possible to do a bad thing.

This wins one of the long standing bug awards.  2003!

Fixes: #11602
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Jul 22, 2022
1 parent b8443f7 commit d2aeac3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ospfclient/ospf_apiclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ 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;
Expand Down

0 comments on commit d2aeac3

Please sign in to comment.