From afd78bd6f0a30ba57adaea870c05cbbb925cc769 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Tue, 2 Jun 2020 20:17:51 +0100 Subject: libctf, create: do not corrupt function types' arglists at insertion time ctf_add_function assumes that function types' arglists are of type ctf_id_t. Since they are CTF IDs, they are 32 bits wide, a uint32_t: unfortunately ctf_id_t is a forward-compatible user-facing 64 bits wide, and should never ever reach the CTF storage level. All the CTF code other than ctf_add_function correctly assumes that function arglists outside dynamic containers are 32 bits wide, so the serialization machinery ends up cutting off half the arglist, corrupting all args but the first (a good sign is a bunch of args of ID 0, the unimplemented type, popping up). Fix this by copying the arglist into place item by item, casting it properly, at the same time as we validate the arg types. Fix the type of the dtu_argv in the dynamic container and drop the now-unnecessary cast in the serializer. libctf/ * ctf-impl.h (ctf_dtdef_t) : Fix type. * ctf-create.c (ctf_add_function): Check for unimplemented type and populate at the same time. Populate one-by-one, not via memcpy. (ctf_serialize): Remove unnecessary cast. * ctf-types.c (ctf_func_type_info): Likewise. (ctf_func_type_args): Likewise. Fix comment typo. --- libctf/ctf-impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libctf/ctf-impl.h') diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index b20a4f0..fdd48f0 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -172,7 +172,7 @@ typedef struct ctf_dtdef ctf_list_t dtu_members; /* struct, union, or enum */ ctf_arinfo_t dtu_arr; /* array */ ctf_encoding_t dtu_enc; /* integer or float */ - ctf_id_t *dtu_argv; /* function */ + uint32_t *dtu_argv; /* function */ ctf_slice_t dtu_slice; /* slice */ } dtd_u; } ctf_dtdef_t; -- cgit v1.1