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

[PATCH] Fix complist menuselect segmentation fault



Without this patch :

I use :

  zstyle ':completion:*:hosts' menu yes=long yes=20 select search

Imagine I have 2 hosts : "ab" and "bb"

When I try to use the completion menu ("isearch") and type "aa" the shell
crash (segmentation fault).

The first "a" match only host "ab", so when a type the second "a", mcol
and mline == 0.

The first time the code enter "if (x == ex && y == ey)", it leave the if
with x = y = ex = ey = 0.
Then "++x" (line 2331) increment x, and x and y can't match ex and ey
anymore since they can only increase.
→ segmentation fault
---
 Src/Zle/complist.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 035038815..a83daeff9 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -2334,11 +2334,6 @@ msearch(Cmatch **ptr, char *ins, int back, int rep, int *wrapp)
             }
         }
         if (x == ex && y == ey) {
-            if (wrap) {
-                msearchstate = MS_FAILED | owrap;
-                break;
-            }
-            msearchstate |= MS_WRAPPED;
 
             if (back) {
                 x = mcols - 1;
@@ -2350,6 +2345,13 @@ msearch(Cmatch **ptr, char *ins, int back, int rep, int *wrapp)
             }
             ex = mcol;
             ey = mline;
+
+            if (wrap || (x == ex && y == ey)) {
+                msearchstate = MS_FAILED | owrap;
+                break;
+            }
+
+            msearchstate |= MS_WRAPPED;
             wrap = 1;
             *wrapp = 1;
         }
-- 
2.13.2



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