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

PATCH: Re: Seg Fault in paramsubst()



Felix Rosencrantz wrote:

> When using this in my completer I would sometimes get seg faults.  Below
> is a stack trace from gdb.  I think this stack trace would only occur if there
> were either no matches or just one.  Though it might just happen in one of
> those situations.

bufferwords() might return a NULL pointer, so we should check if it did.
Everywhere.


Bye
  Sven

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.21
diff -u -r1.21 subst.c
--- Src/subst.c	2001/08/07 10:18:32	1.21
+++ Src/subst.c	2001/08/28 08:32:38
@@ -1833,7 +1833,7 @@
 	} else
 	    list = bufferwords(NULL, val, NULL);
 
-	if (!firstnode(list))
+	if (!list || !firstnode(list))
 	    val = dupstring("");
 	else if (!nextnode(firstnode(list)))
 	    val = getdata(firstnode(list));
Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.21
diff -u -r1.21 parameter.c
--- Src/Modules/parameter.c	2001/07/09 16:05:14	1.21
+++ Src/Modules/parameter.c	2001/08/28 08:32:38
@@ -1105,9 +1105,9 @@
     int i = addhistnum(curhist, -1, HIST_FOREIGN), iw;
     Histent he = gethistent(i, GETHIST_UPWARD);
 
-    ll = bufferwords(NULL, NULL, NULL);
-    for (n = firstnode(ll); n; incnode(n))
-	pushnode(l, getdata(n));
+    if ((ll = bufferwords(NULL, NULL, NULL)))
+        for (n = firstnode(ll); n; incnode(n))
+            pushnode(l, getdata(n));
 
     while (he) {
 	for (iw = he->nwords - 1; iw >= 0; iw--) {
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.4
diff -u -r1.4 zle_misc.c
--- Src/Zle/zle_misc.c	2000/05/10 15:01:19	1.4
+++ Src/Zle/zle_misc.c	2001/08/28 08:32:39
@@ -549,13 +549,13 @@
     int i;
     char *p = NULL;
 
-    l = bufferwords(NULL, NULL, &i);
+    if ((l = bufferwords(NULL, NULL, &i)))
+        for (n = firstnode(l); n; incnode(n))
+            if (!i--) {
+                p = getdata(n);
+                break;
+            }
 
-    for (n = firstnode(l); n; incnode(n))
-	if (!i--) {
-	    p = getdata(n);
-	    break;
-	}
     if (p) {
 	int len = strlen(p);
 

-- 
Sven Wischnowsky                    wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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