disable completely callback() event processing if semaphore >=3; this value is set in "proc tclpropeval2" when displaying the script execution warning to avoid nested translate() calls.

This commit is contained in:
stefan schippers 2026-07-25 10:17:01 +02:00
parent 36d710d2eb
commit e534345b2a
3 changed files with 11 additions and 8 deletions

View File

@ -4713,6 +4713,11 @@ int callback(const char *win_path, int event, int mx, int my, KeySym key, int bu
(persistent_command && (xctx->last_command & STARTWIRE));
struct stat buf;
if(xctx->semaphore >= 3) {
dbg(0, "reentrant callback() call disabled, semaphore = %d\n", xctx->semaphore);
return 0;
}
/* this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease
* events. Some remote connection softwares do not generate the correct coordinates
* on such events */
@ -4809,10 +4814,6 @@ int callback(const char *win_path, int event, int mx, int my, KeySym key, int bu
break;
case ConfigureNotify:
if(xctx->semaphore >= 2 && !redraw_only) {
xctx->semaphore--;
return 0;
}
dbg(1,"callback(): ConfigureNotify event: %s %dx%d\n", win_path, button, aux);
resetwin(1, 1, 0, 0, 0);
draw();

View File

@ -4492,7 +4492,7 @@ const char *translate(int inst, const char* s)
char *value1 = NULL;
int sim_is_ngspice, sim_is_vacask /*, sim_is_xyce */;
char *instname = NULL;
if(!s && inst == -1) {
if(result) my_free(_ALLOC_ID_, &result);
#ifdef __unix__
@ -4507,7 +4507,6 @@ const char *translate(int inst, const char* s)
if(!s || !xctx || !xctx->inst) {
return empty;
}
#ifdef __unix__
if(!get_sp_cur) {
get_sp_cur = my_malloc(_ALLOC_ID_, sizeof(regex_t));

View File

@ -6960,7 +6960,10 @@ proc tclpropeval2 {s} {
return $res
} elseif { $xschem_execute_scripts eq {ask}} {
if {[info exists has_x]} {
xschem set semaphore [expr {[xschem get semaphore] +1}]
# completely disable event processing in callback()
# the alert box causes an Expose event, wicht triggers draw() and translate()
# but this procedure may be called from within a translate() call...
xschem set semaphore [expr {[xschem get semaphore] + 3}]
set msg " Allow xschem to execute scripts embedded in schematics?\n\n"
append msg " WARNING:\n"
append msg " Allowing script execution is a potential security vulnerability,\n"
@ -6972,7 +6975,7 @@ proc tclpropeval2 {s} {
append msg " Current (default) setting is 'ask'."
set answer [alert_ $msg {} 0 1]
xschem set semaphore [expr {[xschem get semaphore] -1}]
xschem set semaphore [expr {[xschem get semaphore] - 3}]
# set answer [tk_messageBox -parent [xschem get topwindow] -message $msg -type yesno]
if {$answer eq {1}} {
set xschem_execute_scripts yes