changeset 32419:777e62ee2f7f

Add extra RET to scripts to avoid out of bound reads As seen by asan run compiled by Clang. * pt-bytecode-walk.cc: Extra RET
author Petter T.
date Tue, 17 Oct 2023 13:27:59 +0200
parents f593161d7b40
children cdea5878d55a
files libinterp/parse-tree/pt-bytecode-walk.cc
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-bytecode-walk.cc	Tue Oct 17 23:24:10 2023 +0200
+++ b/libinterp/parse-tree/pt-bytecode-walk.cc	Tue Oct 17 13:27:59 2023 +0200
@@ -2298,6 +2298,11 @@
 
   // EXIT_SCRIPT_FRAME is put before each RET during the walk.
 
+  // When the last byte of opcode, a 'RET', is to be executed, the VM reads the
+  // next byte of code and puts it in 'arg0'.  So, we need to add a dummy
+  // opcode afterwards to prevent out-of-bounds reads.
+  PUSH_CODE (INSTR::RET);
+
   // Set the amount of locals that has a placeholder since earlier
   SET_CODE_SHORT (m_offset_n_locals, m_n_locals);