Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 3/5] makezleparams(): don't dereference NULL $registers



When traps nest while ZLE is active, zlebeforetrap() calls
makezleparams() again; createspecialhash() then returns NULL for
"registers" (it already exists from the enclosing call) and the
following assignment crashes.  The other ZLE parameters already cope
with createparam() returning NULL; do likewise.

Co-Authored-By: Claude Opus 5.5 <noreply@xxxxxxxxxxxxx>
---

Notes:
    Reproducer: start "zsh -f", paste the lines below, then hold down
    Ctrl-C for a few seconds.  Without this patch (preceding ones applied),
    zsh 5.9.2 segfaults in makezleparams().
    
        setopt interactivecomments
        # 3: nested traps while zle is active: makezleparams() dereferences a
        #    NULL $registers created by the enclosing trap's scope.
        #    (The trap re-installs itself so INT is not ignored while it runs.)
        T='trap "$T" INT; repeat 300 :; return 130'
        trap "$T" INT

 Src/Zle/zle_params.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index b828e145c..5c1592da2 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -223,8 +223,11 @@ makezleparams(int ro)
 
     reg_param = createspecialhash("registers", get_registers, &scan_registers,
 	    PM_LOCAL|PM_REMOVABLE);
-    reg_param->gsu.h = &registers_gsu;
-    reg_param->level = locallevel + 1;
+    /* NULL if already made by an enclosing (e.g. interrupted) scope */
+    if (reg_param) {
+	reg_param->gsu.h = &registers_gsu;
+	reg_param->level = locallevel + 1;
+    }
 }
 
 /* Special unset function for ZLE special parameters: act like the standard *
-- 
2.55.0





Messages sorted by: Reverse Date, Date, Thread, Author