From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5235 invoked by alias); 10 Mar 2013 19:12:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31139 Received: (qmail 25690 invoked from network); 10 Mar 2013 19:12:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.175 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-proxyuser-ip:date:from:to:subject:message-id :in-reply-to:references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=dN3FmSiRLL8pd2nR9WCQhqlu4EdP9yy5oaZ+VeMdEbM=; b=EdEzTVVk+Js22iTAJ5hC05On7jy2sLcY8EAAfIvFKsgy49Q8yawrGiZOywMldrNvYV PzjhwWX3BTFY+lmG/UAMDD+MaW7FiZcDtGHYNx1PkhwA1zIKgpZ1+v0GHylCfbfMO3nn BEncm3/QFN+7TfCqnela9cR8XgBwLEqIOoYGkOOk9nOAX3s6cBAqBsC75nm9nuQ2lo+Z 1hoCtH5Pqkp7WDYYr2MgrbQha2D5xG4SB4QAhAN0S4EcO3bG/Ppzr/4dh/p4rTH20I2w Pig1NSSNhP8Jf23RZO9Z4jXZUyacgat8RdXnfgRM06ris0gWRqWYCf4v1bcc2wVKJVeK LCFw== X-Received: by 10.181.11.198 with SMTP id ek6mr13770581wid.1.1362940967279; Sun, 10 Mar 2013 11:42:47 -0700 (PDT) X-ProxyUser-IP: 86.26.6.143 Date: Sun, 10 Mar 2013 18:42:44 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: PATCH: Don't crash when math recursion limit is exceeded Message-ID: <20130310184244.41e1d554@pws-pc.ntlworld.com> In-Reply-To: <1362917197-2576-1-git-send-email-mikachu@gmail.com> References: <1362917197-2576-1-git-send-email-mikachu@gmail.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnbbUU3Qz7yta3H8PhIl5jawmutcHyu1G0R4j9CvbaL3RBA0mQgdQUq81Ep93BV6MkP1Ie6 On Sun, 10 Mar 2013 13:06:37 +0100 Mikael Magnusson wrote: > This used to never trigger for me when compiling in debug mode, but I > finally had better luck today and tracked it down. > > *ep seems to already be NULL, but I couldn't quite figure out where it > was set to NULL so I figured it can't hurt to make it explicitly NULL > at that point. I suppose setting *ep = ""; would also work (without the > second hunk)? Another way of doing it would probably be to set "*ep = s", which is consistent with what *ep is supposed to be doing. If you set it to NULL it's probably safest to change the value returned by the other calls of mathevall() around line 960 pre-patch, which also outputs the "bad math expression" error. I don't see why they shouldn't be fully consistent; zerr() already tests for errflag, so they shouldn't need to test for that, but either neither or both should. -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/ > --- > Src/math.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/Src/math.c b/Src/math.c > index f8a4eef..43cede9 100644 > --- a/Src/math.c > +++ b/Src/math.c > @@ -362,6 +362,7 @@ mathevall(char *s, enum prec_type prec_tp, char **ep) > if (mlevel >= MAX_MLEVEL) { > xyyval.type = MN_INTEGER; > xyyval.u.l = 0; > + *ep = NULL; > > zerr("math recursion limit exceeded"); > > @@ -1352,7 +1353,7 @@ matheval(char *s) > } > x = mathevall(s, MPREC_TOP, &junk); > mtok = xmtok; > - if (*junk) > + if (junk && *junk) > zerr("bad math expression: illegal character: %c", *junk); > return x; > } > -- > 1.7.10.GIT