Revert "libctf: do not corrupt strings across ctf_serialize"

This reverts commit 986e9e3aa0.

(We do not revert the testcase -- it remains valid -- but we are
taking a different, less complex and more robust approach.)

This also deletes the pending refs abstraction without (yet)
replacing it, so some tests will fail for a commit or two.
This commit is contained in:
Nick Alcock
2024-01-30 13:40:56 +00:00
parent 629acbe4a3
commit 3301ddba1b
5 changed files with 14 additions and 125 deletions

View File

@@ -464,8 +464,7 @@ ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind,
type = ++fp->ctf_typemax;
type = LCTF_INDEX_TO_TYPE (fp, type, (fp->ctf_flags & LCTF_CHILD));
dtd->dtd_data.ctt_name = ctf_str_add_pending (fp, name,
&dtd->dtd_data.ctt_name);
dtd->dtd_data.ctt_name = ctf_str_add_ref (fp, name, &dtd->dtd_data.ctt_name);
dtd->dtd_type = type;
if (dtd->dtd_data.ctt_name == 0 && name != NULL && name[0] != '\0')
@@ -1080,21 +1079,11 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
return -1; /* errno is set for us. */
en = (ctf_enum_t *) dtd->dtd_vlen;
if (dtd->dtd_vlen != old_vlen)
{
ptrdiff_t move = (signed char *) dtd->dtd_vlen - (signed char *) old_vlen;
/* Remove pending refs in the old vlen region and reapply them. */
for (i = 0; i < vlen; i++)
ctf_str_move_pending (fp, &en[i].cte_name, move);
}
for (i = 0; i < vlen; i++)
if (strcmp (ctf_strptr (fp, en[i].cte_name), name) == 0)
return (ctf_set_errno (ofp, ECTF_DUPLICATE));
en[i].cte_name = ctf_str_add_pending (fp, name, &en[i].cte_name);
en[i].cte_name = ctf_str_add_ref (fp, name, &en[i].cte_name);
en[i].cte_value = value;
if (en[i].cte_name == 0 && name != NULL && name[0] != '\0')
@@ -1154,16 +1143,6 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
return (ctf_set_errno (ofp, ctf_errno (fp)));
memb = (ctf_lmember_t *) dtd->dtd_vlen;
if (dtd->dtd_vlen != old_vlen)
{
ptrdiff_t move = (signed char *) dtd->dtd_vlen - (signed char *) old_vlen;
/* Remove pending refs in the old vlen region and reapply them. */
for (i = 0; i < vlen; i++)
ctf_str_move_pending (fp, &memb[i].ctlm_name, move);
}
if (name != NULL)
{
for (i = 0; i < vlen; i++)
@@ -1193,7 +1172,7 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
return -1; /* errno is set for us. */
}
memb[vlen].ctlm_name = ctf_str_add_pending (fp, name, &memb[vlen].ctlm_name);
memb[vlen].ctlm_name = ctf_str_add_ref (fp, name, &memb[vlen].ctlm_name);
memb[vlen].ctlm_type = type;
if (memb[vlen].ctlm_name == 0 && name != NULL && name[0] != '\0')
return -1; /* errno is set for us. */