diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2024-06-11 20:11:29 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2024-06-18 13:20:31 +0100 |
commit | 327356780ab4436b59b666a756323b8bda68cbd4 (patch) | |
tree | eb8be1a75188b04b109abc34f5795250e0ef40ac /libctf | |
parent | f8da1a05db64d8c5c700e07a008a1938858a7adf (diff) | |
download | gdb-327356780ab4436b59b666a756323b8bda68cbd4.zip gdb-327356780ab4436b59b666a756323b8bda68cbd4.tar.gz gdb-327356780ab4436b59b666a756323b8bda68cbd4.tar.bz2 |
libctf: don't leak enums if ctf_add_type fails
If ctf_add_type failed in the middle of enumerator addition, the
destination would end up containing the source enum type and some
but not all of its enumerator constants.
Use snapshots to roll back the enum addition as a whole if this happens.
Before now, it's been pretty unlikely, but in an upcoming commit we will ban
addition of enumerators that already exist in a given dict, making failure
of ctf_add_enumerator and thus of this part of ctf_add_type much more
likely.
libctf/
* ctf-create.c (ctf_add_type_internal): Roll back if enum or
enumerator addition fails.
Diffstat (limited to 'libctf')
-rw-r--r-- | libctf/ctf-create.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index ee79e49..073006b 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -1944,10 +1944,15 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type } else { + ctf_snapshot_id_t snap = ctf_snapshot (dst_fp); + dst_type = ctf_add_enum (dst_fp, flag, name); if ((dst.ctb_type = dst_type) == CTF_ERR || ctf_enum_iter (src_fp, src_type, enumadd, &dst)) - return CTF_ERR; /* errno is set for us */ + { + ctf_rollback (dst_fp, snap); + return CTF_ERR; /* errno is set for us */ + } } break; |