]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
libctf: Improve check for duplicate SOU definitions in ctf_add_type()
authorMark Johnston <markj@FreeBSD.org>
Mon, 4 Oct 2021 16:28:22 +0000 (12:28 -0400)
committerMark Johnston <markj@FreeBSD.org>
Mon, 4 Oct 2021 16:28:22 +0000 (12:28 -0400)
commit105fd928b0b5b35ab529e5f6914788dc49582901
tree2e56ecfe8ce3c238d0093d9846a1aaf18ba33bc2
parent507a22be3850da1f2afc753abcf3372659249c31
libctf: Improve check for duplicate SOU definitions in ctf_add_type()

When copying a struct or union from one CTF container to another,
ctf_add_type() checks whether it matches an existing type in the
destination container.  It does so by looking for a type with the same
name and kind as the new type, and if one exists, it iterates over all
members of the source type and checks whether a member with matching
name and offset exists in the matched destination type.  This can
produce false positives, for example because member types are not
compared, but this is not expected to arise in practice.  If the match
fails, ctf_add_type() returns an error.

The procedure used for member comparison breaks down in the face of
anonymous struct and union members.  ctf_member_iter() visits each
member in the source definition and looks up the corresponding member in
the desination definition by name using ctf_member_info(), but this
function will descend into anonymous members and thus fail to match.
Fix the problem by introducing a custom comparison routine which does
not assume member names are unique.  This should also be faster for
types with many members; in the previous scheme, membcmp() would perform
a linear scan of the desination type's members to perform a lookup by
name.  The new routine steps through the members of both types in a
single loop.

PR: 258763
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
cddl/contrib/opensolaris/common/ctf/ctf_create.c