Skip to content

Commit

Permalink
helper/command: make command_run_line reentrant
Browse files Browse the repository at this point in the history
The `command_run_line` function contains a comment saying it should be
reentrant. However, it isn’t: it NULLs out `current_target_override` and
doesn’t restore it before returning, and it changes the `context`
associated data of the `interp` object and then deletes that associated
data before returning rather than restoring it to its previous value.

Change-Id: I84fd46ef7173f08cf7c57b9a5b76e4986a60816f
Signed-off-by: Christopher Head <[email protected]>
Reviewed-on: http:https://openocd.zylin.com/5223
Tested-by: jenkins
Reviewed-by: Antonio Borneo <[email protected]>
Reviewed-by: Tomas Vanek <[email protected]>
  • Loading branch information
Christopher Head authored and tom-van committed Jun 20, 2019
1 parent 23b6aa9 commit 77a8914
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/helper/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,11 @@ int command_run_line(struct command_context *context, char *line)
* happen when the Jim Tcl interpreter is provided by eCos for
* instance.
*/
struct target *saved_target_override = context->current_target_override;
context->current_target_override = NULL;

Jim_Interp *interp = context->interp;
struct command_context *old_context = Jim_GetAssocData(interp, "context");
Jim_DeleteAssocData(interp, "context");
retcode = Jim_SetAssocData(interp, "context", NULL, context);
if (retcode == JIM_OK) {
Expand All @@ -667,7 +669,11 @@ int command_run_line(struct command_context *context, char *line)
Jim_DeleteAssocData(interp, "retval");
}
Jim_DeleteAssocData(interp, "context");
int inner_retcode = Jim_SetAssocData(interp, "context", NULL, old_context);
if (retcode == JIM_OK)
retcode = inner_retcode;
}
context->current_target_override = saved_target_override;
if (retcode == JIM_OK) {
const char *result;
int reslen;
Expand Down

0 comments on commit 77a8914

Please sign in to comment.