[3/8] libctf, serialize: functions with no args have a NULL dtd_vlen

Message ID 20210324012158.35472-3-nick.alcock@oracle.com
State New
Headers show
Series
  • [1/8] libctf, dump: do not emit size or alignment if it would error
Related show

Commit Message

Richard Earnshaw via Binutils March 24, 2021, 1:21 a.m.
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-23  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.
---
 libctf/ctf-serialize.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

-- 
2.31.0.253.gdec51257f3

Patch

diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index 0811b7b6efe..9f50280176c 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;