aboutsummaryrefslogtreecommitdiff
path: root/libctf
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2021-03-25 16:32:46 +0000
committerNick Alcock <nick.alcock@oracle.com>2021-03-25 16:32:48 +0000
commit86f64bf43f70ecefa9232f5b8621b179dfff52fd (patch)
treea5bdee1f432ebdbe78db8a65e6d0133907c9c9a5 /libctf
parent24c877f9b19dc38f9c40e25116175481c8bb78f2 (diff)
downloadgdb-86f64bf43f70ecefa9232f5b8621b179dfff52fd.zip
gdb-86f64bf43f70ecefa9232f5b8621b179dfff52fd.tar.gz
gdb-86f64bf43f70ecefa9232f5b8621b179dfff52fd.tar.bz2
libctf, serialize: functions with no args have a NULL dtd_vlen
Every place that accesses a function's dtd_vlen accesses it only if the number of args is nonzero, except the serializer, which always tries to memcpy it. The number of bytes it memcpys in this case is zero, but it is still undefined behaviour to copy zero bytes from a null pointer. So check for this case explicitly. libctf/ChangeLog 2021-03-25 Nick Alcock <nick.alcock@oracle.com> PR libctf/27628 * ctf-serialize.c (ctf_emit_type_sect): Allow for a NULL vlen in CTF_K_FUNCTION types.
Diffstat (limited to 'libctf')
-rw-r--r--libctf/ChangeLog6
-rw-r--r--libctf/ctf-serialize.c4
2 files changed, 9 insertions, 1 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 909c4fc..a9e76ec 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,11 @@
2021-03-25 Nick Alcock <nick.alcock@oracle.com>
+ PR libctf/27628
+ * ctf-serialize.c (ctf_emit_type_sect): Allow for a NULL vlen in
+ CTF_K_FUNCTION types.
+
+2021-03-25 Nick Alcock <nick.alcock@oracle.com>
+
* ctf-dump.c (ctf_dump_format_type): Don't emit size or alignment
on error.
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index 0811b7b..9f50280 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -849,7 +849,9 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr)
break;
case CTF_K_FUNCTION:
- memcpy (t, dtd->dtd_vlen, sizeof (uint32_t) * (vlen + (vlen & 1)));
+ /* Functions with no args also have no vlen. */
+ if (dtd->dtd_vlen)
+ memcpy (t, dtd->dtd_vlen, sizeof (uint32_t) * (vlen + (vlen & 1)));
t += sizeof (uint32_t) * (vlen + (vlen & 1));
break;