From e534345b2a7baaa40ebe5c8f1be4af23d34bb5b2 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 25 Jul 2026 10:17:01 +0200 Subject: [PATCH] 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. --- src/callback.c | 9 +++++---- src/token.c | 3 +-- src/xschem.tcl | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/callback.c b/src/callback.c index ce1b4a80..4726a6fe 100644 --- a/src/callback.c +++ b/src/callback.c @@ -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(); diff --git a/src/token.c b/src/token.c index 57517718..71cef89c 100644 --- a/src/token.c +++ b/src/token.c @@ -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)); diff --git a/src/xschem.tcl b/src/xschem.tcl index 9d6208b7..d38f95ec 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -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