aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-archive.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2025-05-12 12:31:00 +0100
committerNick Alcock <nick.alcock@oracle.com>2025-05-20 14:35:45 +0100
commite4edfb3ee5328a944e45bc1de15eb246e4a0e0b9 (patch)
tree4a3a28922dafd7511e4401d23d29566159569cf6 /libctf/ctf-archive.c
parent3e488d8ccd0fb25d9c2d33feceb9eac3e336c1b0 (diff)
downloadgdb-users/nalcock/try-ctf-err-ptr.zip
gdb-users/nalcock/try-ctf-err-ptr.tar.gz
gdb-users/nalcock/try-ctf-err-ptr.tar.bz2
libctf: archive, open: when opening, always set errp to somethingusers/nalcock/try-ctf-err-ptr
ctf_arc_import_parent, called by the cached-opening machinery used by ctf_archive_next and archive-wide lookup functions like ctf_arc_lookup_symbol, has an err-pointer parameter like all other opening functions. Unfortunately it unconditionally initializes it whenever provided, even if there was no error, which can lead to its being initialized to an uninitialized value. This is not technically an API-contract violation, since we don't define what happens to the error value except when an error happens, but it is still unpleasant. Initialize it only when there is an actual error, so we never initialize it to an uninitialized value. While we're at it, improve all the opening pathways: on success, set errp to 0, rather than leaving it what it was, reducing the likelihood of uninitialized error param returns in callers too. (This is inconsistent with the treatment of ctf_errno(), but the err value being a parameter passed in from outside makes the divergence acceptable: in open functions, you're never going to be overwriting some old error value someone might want to keep around across multiple calls, some of which are successful and some of which are not.) Soup up existing tests to verify all this. Thanks to Bruce McCulloch for the original patch, and Stephen Brennan for the report. libctf/ PR libctf/32903 * ctf-archive.c (ctf_arc_open_internal): Zero errp on success. (ctf_dict_open_sections): Zero errp at the start. (ctf_arc_import_parent): Intialize err. * ctf-open.c (ctf_bufopen): Zero errp at the start. * testsuite/libctf-lookup/add-to-opened.c: Make sure one-element archive opens update errp. * testsuite/libctf-writable/ctf-compressed.c: Make sure real archive opens update errp.
Diffstat (limited to 'libctf/ctf-archive.c')
-rw-r--r--libctf/ctf-archive.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index dc01e2e..6c4595f 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -485,6 +485,10 @@ ctf_arc_open_internal (const char *filename, int *errp)
is private.) */
arc->ctfa_magic = s.st_size;
close (fd);
+
+ if (errp)
+ *errp = 0;
+
return arc;
err_unmap:
@@ -588,6 +592,9 @@ ctf_dict_open_sections (const ctf_archive_t *arc,
const char *name,
int *errp)
{
+ if (errp)
+ *errp = 0;
+
if (arc->ctfi_is_archive)
{
ctf_dict_t *ret;
@@ -761,7 +768,7 @@ ctf_arc_import_parent (const ctf_archive_t *arc, ctf_dict_t *fp, int *errp)
{
if ((fp->ctf_flags & LCTF_CHILD) && fp->ctf_parname && !fp->ctf_parent)
{
- int err;
+ int err = 0;
ctf_dict_t *parent = ctf_dict_open_cached ((ctf_archive_t *) arc,
fp->ctf_parname, &err);
if (errp)