From 72ab2e7cf00ca3e4b8ba8492d0e32efca7d227a7 Mon Sep 17 00:00:00 2001 From: blb4github <35904565+blb4github@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:45:02 +0100 Subject: [PATCH] Rules VM: reject conditional jumps exceeding the uint8 bytecode range --- src/rules/rules.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rules/rules.cpp b/src/rules/rules.cpp index 891817e..e55c73a 100755 --- a/src/rules/rules.cpp +++ b/src/rules/rules.cpp @@ -3119,7 +3119,13 @@ static int16_t rule_create(char **text, struct rules_t *obj) { jmp = (struct vm_top_t *)&obj->bc.buffer[lastjmp]; if((int8_t)getval(jmp->b) == depth) { int16_t step = getval(obj->bc.nrbytes); - setval(jmp->a, ((step-lastjmp)/sizeof(struct vm_top_t))+1); + int32_t jump = (step-lastjmp)/(int32_t)sizeof(struct vm_top_t)+1; + if(jump > UINT8_MAX) { + logprintf_P(F("ERROR: rule #%d: conditional jump of %ld instructions exceeds 255"), + getval(obj->nr), (long)jump); + return -1; + } + setval(jmp->a, jump); setval(jmp->b, 0); break; } @@ -4253,8 +4259,14 @@ static int16_t rule_create(char **text, struct rules_t *obj) { if(gettype(obj->bc.buffer[lastjmp]) == OP_JMP) { jmp = (struct vm_top_t *)&obj->bc.buffer[lastjmp]; if((int8_t)getval(jmp->b) == depth) { + int32_t jump = (step-lastjmp)/(int32_t)sizeof(struct vm_top_t); + if(jump > UINT8_MAX) { + logprintf_P(F("ERROR: rule #%d: conditional jump of %ld instructions exceeds 255"), + getval(obj->nr), (long)jump); + return -1; + } setval(jmp->b, 0); - setval(jmp->a, ((step-lastjmp)/sizeof(struct vm_top_t))); + setval(jmp->a, jump); } } }