From 2ef17d02008155a11392fedf65cd7c6d46594ae4 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Fri, 15 May 2020 15:00:12 +0200 Subject: [PATCH] Ignore backward jumps in computing serializer size When defining a new topic, typically the serializer instructions that are usually in constant memory and generated by the IDL compiler are copied into memory managed by the Cyclone implementation. For this it needs to compute the size of the serializer, which the IDL compiler doesn't provide. It does this by effectively dry-running the program. (Note that it doesn't validate the program.) All but the JSR operations move the program counter forward, but the JSR operation can cause it to go backward instead and allows implementing recursive types (the IDL compiler doesn't support them, but one might decide to work around that limitation). When dry-running the program, following a backwards jump can cause a non-terminating loop. The jump could potentially be to an unexplored address and so ignoring all backwards jumps potentially means it skips part of the program. As this is not a validator and the program can always be arranged so that a following a backwards jump is not relevant to computing the size correctly, this is reasonable approximation. Signed-off-by: Erik Boasson --- src/core/ddsi/src/ddsi_cdrstream.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/ddsi/src/ddsi_cdrstream.c b/src/core/ddsi/src/ddsi_cdrstream.c index 6cdfb80..9556766 100644 --- a/src/core/ddsi/src/ddsi_cdrstream.c +++ b/src/core/ddsi/src/ddsi_cdrstream.c @@ -364,7 +364,8 @@ static void dds_stream_countops1 (const uint32_t * __restrict ops, const uint32_ break; } case DDS_OP_JSR: { - dds_stream_countops1 (ops + DDS_OP_JUMP (insn), ops_end); + if (DDS_OP_JUMP (insn) > 0) + dds_stream_countops1 (ops + DDS_OP_JUMP (insn), ops_end); ops++; break; }