summaryrefslogtreecommitdiff
path: root/lib/printf/printfcommon.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@nvidia.com>2020-09-02 13:16:35 -0400
committerQuentin Young <qlyoung@nvidia.com>2020-09-02 13:16:35 -0400
commit1e9be514b3047e450f89fc3cebcdbd165a58d51b (patch)
tree7497406933199bf470bdadd8f3d0feaf8588c6d0 /lib/printf/printfcommon.h
parent2e5b029865137c1aa383454d3552487a2b998ee4 (diff)
bgpd: modify attr fields before hash insert
bgp_attr_intern(attr) takes an attribute, duplicates it, and inserts it into the attribute hash table, returning the inserted attr. This is done when processing a bgp update. We store the returned attribute in the path info struct. However, later on we modify one of the fields of the attribute. This field is inspected by attrhash_cmp, the function that allows the hash table to select the correct item from the hash chain for a given key when doing a lookup on an item. By modifying the field after it's been inserted, we open the possibility that two items in the same chain that at insertion time were differential by attrhash_cmp becomes equal according to that function. When performing subsequent hash lookups, it is then indeterminate which of the equivalent items the hash table will select from the chain (in practice it is the first one but this may not be the one we want). Thus, it is illegal to modify data used by a hash comparison function after inserting that data into a hash table. In fact this is occurring for attributes. We insert two attributes that hash to the same key and thus end up in the same hash chain. Then we modify one of them such that the two items now compare equal. Later one we want to release the second item from the chain before XFREE()'ing it, but since the two items compare equal we get the first item back, then free the second one, which constitutes two bugs, the first being the wrong attribute removed from the hash table and the second being a dangling pointer stored in the hash table. To rectify this we need to perform any modifications to an attr before it is inserted into the table, i.e., before calling bgp_attr_intern(). This patch does that by moving the sole modification to the attr that occurs after the insert (that I have seen) before that call. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
Diffstat (limited to 'lib/printf/printfcommon.h')
0 files changed, 0 insertions, 0 deletions