Skip to content

Instantly share code, notes, and snippets.

@msteveb
Created January 17, 2018 22:43
Show Gist options
  • Save msteveb/a430815b645902033ffabcdbe755412d to your computer and use it in GitHub Desktop.
Save msteveb/a430815b645902033ffabcdbe755412d to your computer and use it in GitHub Desktop.
jim tcl: prevent expr stack overflow
From c57bc5d040d03301de1d75dc77c1ea4d9ca0f7db Mon Sep 17 00:00:00 2001
From: Steve Bennett <steveb@workware.net.au>
Date: Thu, 18 Jan 2018 08:41:24 +1000
Subject: [PATCH] expr: prevent stack overflow
Limit the depth of the expressions to a reasonable level to prevent
stack overflow
Signed-off-by: Steve Bennett <steveb@workware.net.au>
---
jim.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/jim.c b/jim.c
index 7de75e65..9ae90636 100644
--- a/jim.c
+++ b/jim.c
@@ -8830,7 +8830,10 @@ static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, in
/* Calculate the stack length expected after pushing the number of expected terms */
int exp_stacklen = builder->stack.len + exp_numterms;
- builder->level++;
+ if (builder->level++ > 200) {
+ Jim_SetResultString(interp, "Expression too complex", -1);
+ return JIM_ERR;
+ }
while (builder->token->type != JIM_TT_EOL) {
ParseToken *t = builder->token++;
--
2.13.5 (Apple Git-94)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment