public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: binutils@sourceware.org
Cc: stephen.brennan@oracle.com
Subject: [PATCH 01/11] libctf: strtab corruption when strings are added to ctf_open()ed dicts
Date: Thu, 13 Jun 2024 19:54:20 +0100	[thread overview]
Message-ID: <20240613185430.85352-2-nick.alcock@oracle.com> (raw)
In-Reply-To: <20240613185430.85352-1-nick.alcock@oracle.com>

ctf_str_add_ref and ctf_str_add_movable_ref take a string and are supposed
to return a strtab offset.  These offsets are "provisional": the ref
mechanism records the address of the location in which the ref is stored and
modifies it when the strtab is finally written out.  Provisional refs in new
dicts start at 0 and go up via strlen() as new refs are added: this is fine,
because the strtab is empty and none of these values will overlap any
existing string offsets (since there are none).  Unfortunately, when a dict
is ctf_open()ed, we fail to set the initial provisional strtab offset to a
higher value than any existing string offset: it starts at zero again!
It's a shame that we already *have* strings at those offsets...

This is all fixed up once the string is reserialized, but if you look up
newly-added strings before serialization, you get corrupted partial string
results from the existing ctf_open()ed dict.

Observed (and thus regtested) by an upcoming test (in this patch series).

Exposed by the recently-introduced series that permits modification of
ctf_open()ed dicts, which has not been released anywhere.  Before that,
any attempt to do such things would fail with ECTF_RDONLY.

libctf/
	* ctf-string.c (ctf_str_create_atoms): Initialize
        ctf_str_prov_offset.
---
 libctf/ctf-string.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libctf/ctf-string.c b/libctf/ctf-string.c
index 0c5bd58cdaf..2d96e45617c 100644
--- a/libctf/ctf-string.c
+++ b/libctf/ctf-string.c
@@ -195,6 +195,8 @@ ctf_str_create_atoms (ctf_dict_t *fp)
       atom->csa_offset = i;
     }
 
+  fp->ctf_str_prov_offset = fp->ctf_str[CTF_STRTAB_0].cts_len + 1;
+
   return 0;
 
  oom_str_add:
-- 
2.45.1.275.g567cb0950c


  reply	other threads:[~2024-06-13 18:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 18:54 [PATCH libctf 00/11] enumerator query API, plus some bugfixes Nick Alcock
2024-06-13 18:54 ` Nick Alcock [this message]
2024-06-13 18:54 ` [PATCH 02/11] include: fix libctf ECTF_NOENUMNAM error message Nick Alcock
2024-06-13 18:54 ` [PATCH 03/11] libctf: doc: fix ctf_stype_t typedef string in spec Nick Alcock
2024-06-13 18:54 ` [PATCH 04/11] libctf: dedup: enums with overlapping enumerators are conflicting Nick Alcock
2024-06-13 18:54 ` [PATCH 05/11] libctf: don't leak enums if ctf_add_type fails Nick Alcock
2024-06-13 18:54 ` [PATCH 06/11] libctf: fix dict leak on archive-wide symbol lookup error path Nick Alcock
2024-06-13 18:54 ` [PATCH 07/11] libctf: suppress spurious failure of malloc-counting tests under valgrind Nick Alcock
2024-06-13 18:54 ` [PATCH 08/11] libctf: prohibit addition of enums with overlapping enumerator constants Nick Alcock
2024-06-13 18:54 ` [PATCH 09/11] libctf: make the ctf_next ctn_fp non-const Nick Alcock
2024-06-13 18:54 ` [PATCH 10/11] include: libctf: comment improvements Nick Alcock
2024-06-13 18:54 ` [PATCH 11/11] libctf, include: new functions for looking up enumerators Nick Alcock
2024-06-14 17:51   ` David Faust
2024-06-17 13:43     ` Nick Alcock
2024-06-14 14:14 ` [PATCH libctf 00/11] enumerator query API, plus some bugfixes Tom Tromey
2024-06-14 17:57   ` Nick Alcock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240613185430.85352-2-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=binutils@sourceware.org \
    --cc=stephen.brennan@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).