]> git.proxmox.com Git - mirror_frr.git/commit - ospfd/ospf_dump.c
ospfd: Correct Coverity defects
authorOlivier Dugeon <olivier.dugeon@orange.com>
Tue, 6 Apr 2021 10:09:25 +0000 (12:09 +0200)
committerOlivier Dugeon <olivier.dugeon@orange.com>
Wed, 19 May 2021 07:48:54 +0000 (09:48 +0200)
commit8db278b5e3e2b1a8b2d8ac85789565d5dd268ac6
treee36fe5d6cb6329b2b649f0360554213fa78979dc
parent2794d40202c392e676b8f77ac423adad8ede0545
ospfd: Correct Coverity defects

When browsing or parsing OSPF LSA TLVs, we need to use the LSA length which is
part of the LSA header. This length, encoded in 16 bits, must be first
converted to host byte order with ntohs() function. However, Coverity Scan
considers that ntohs() function return TAINTED data. Thus, when the length is
used to control for() loop, Coverity Scan marks this part of the code as defect
with "Untrusted Loop Bound" due to the usage of Tainted variable. Similar
problems occur when browsing sub-TLV where length is extracted with ntohs().

To overcome this limitation, a size attribute has been added to the ospf_lsa
structure. The size is set when lsa->data buffer is allocated. In addition,
when an OSPF packet is received, the size of the payload is controlled before
contains is processed. For OSPF LSA, this allow a secure buffer allocation.
Thus, new size attribute contains the exact buffer allocation allowing a
strict control during TLV browsing.

This patch adds extra control to bound for() loop during TLV browsing to
avoid potential problem as suggested by Coverity Scan. Controls are based
on new size attribute of the ospf_lsa structure to avoid any ambiguity.

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
16 files changed:
ospfd/ospf_api.c
ospfd/ospf_api.h
ospfd/ospf_apiserver.c
ospfd/ospf_dump.c
ospfd/ospf_ext.c
ospfd/ospf_gr_helper.c
ospfd/ospf_lsa.c
ospfd/ospf_lsa.h
ospfd/ospf_opaque.c
ospfd/ospf_opaque.h
ospfd/ospf_ri.c
ospfd/ospf_ri.h
ospfd/ospf_sr.c
ospfd/ospf_sr.h
ospfd/ospf_te.c
ospfd/ospf_vty.c