Skip to content

Commit

Permalink
xtrace: fix core dump if tracing Jim_EvalObjVector()
Browse files Browse the repository at this point in the history
Where a NULL script is pushed on the stack

Fixes #290

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information
msteveb committed Feb 2, 2024
1 parent adb3252 commit a227bf7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions jim.c
Original file line number Diff line number Diff line change
Expand Up @@ -10714,13 +10714,18 @@ static int JimTraceCallback(Jim_Interp *interp, const char *type, int argc, Jim_
Jim_Obj *nargv[7];
Jim_Obj *traceCmdObj = interp->traceCmdObj;
Jim_Obj *resultObj = Jim_GetResult(interp);
ScriptObj *script = NULL;

/* Where were we called from? */
ScriptObj *script = JimGetScript(interp, interp->evalFrame->scriptObj);
/* This may be NULL for Jim_EvalObjVector() */
if (interp->evalFrame->scriptObj) {
script = JimGetScript(interp, interp->evalFrame->scriptObj);
}

nargv[0] = traceCmdObj;
nargv[1] = Jim_NewStringObj(interp, type, -1);
nargv[2] = script->fileNameObj;
nargv[3] = Jim_NewIntObj(interp, script->linenr);
nargv[2] = script ? script->fileNameObj : interp->emptyObj;
nargv[3] = Jim_NewIntObj(interp, script ? script->linenr : 1);
nargv[4] = resultObj;
nargv[5] = argv[0];
nargv[6] = Jim_NewListObj(interp, argv + 1, argc - 1);
Expand Down Expand Up @@ -10921,6 +10926,7 @@ int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
for (i = 0; i < objc; i++)
Jim_IncrRefCount(objv[i]);

/* Note that we have no source for this command so push NULL as the scriptObj */
JimPushEvalFrame(interp, &frame, NULL);

retcode = JimInvokeCommand(interp, objc, objv);
Expand Down

0 comments on commit a227bf7

Please sign in to comment.