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

Re: [Bug] ZSH segmentation fault



DervishD wrote:
>     While I understand that running such scripts is very unusual, I
> think that just segfaulting is not a correct way of dealing with errors.

I didn't claim it was, indeed I think I implied the opposite.

I can easily work around this one, though even this isn't completely
trivial.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.115
diff -u -r1.115 exec.c
--- Src/exec.c	29 May 2007 14:16:03 -0000	1.115
+++ Src/exec.c	3 Jun 2007 17:32:50 -0000
@@ -3111,7 +3111,13 @@
 	    ;
 	for (;;) {
 	    if (bptr == buf + bsiz) {
-		buf = realloc(buf, 2 * bsiz);
+		char *newbuf = realloc(buf, 2 * bsiz);
+		if (!newbuf) {
+		    /* out of memory */
+		    zfree(buf, bsiz);
+		    return NULL;
+		}
+		buf = newbuf;
 		t = buf + bsiz - (bptr - t);
 		bptr = buf + bsiz;
 		bsiz *= 2;
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.38
diff -u -r1.38 lex.c
--- Src/lex.c	23 Jan 2007 16:07:47 -0000	1.38
+++ Src/lex.c	3 Jun 2007 17:32:51 -0000
@@ -356,6 +356,16 @@
 	    ALLOWHIST
 	    cmdpop();
 	    hwend();
+	    if (!name) {
+		zerr("here document too large");
+		while (hdocs) {
+		    next = hdocs->next;
+		    zfree(hdocs, sizeof(struct heredocs));
+		    hdocs = next;
+		}
+		tok = LEXERR;
+		break;
+	    }
 	    setheredoc(hdocs->pc, REDIR_HERESTR, name);
 	    zfree(hdocs, sizeof(struct heredocs));
 	    hdocs = next;

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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