From owner-freebsd-current@FreeBSD.ORG Sun Sep 18 11:56:52 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A3DED106566B; Sun, 18 Sep 2011 11:56:52 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 3F87D8FC15; Sun, 18 Sep 2011 11:56:52 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id D6CF5358C4E; Sun, 18 Sep 2011 13:56:50 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id CD69517467; Sun, 18 Sep 2011 13:56:50 +0200 (CEST) Date: Sun, 18 Sep 2011 13:56:50 +0200 From: Jilles Tjoelker To: Kostik Belousov Message-ID: <20110918115650.GA36162@stack.nl> References: <20110914123607.GM65366@felucia.tataz.chchile.org> <20110914125953.GX17489@deviant.kiev.zoral.com.ua> <20110914154221.GB7863@felucia.tataz.chchile.org> <20110914200456.GE17489@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110914200456.GE17489@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Peter Pentchev , freebsd-current@freebsd.org, Jeremie Le Hen , David Xu , Oliver Lehmann Subject: Re: Segfault in libthr.so on 9.0-BETA2 (with stunnel FWIW) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Sep 2011 11:56:52 -0000 On Wed, Sep 14, 2011 at 11:04:56PM +0300, Kostik Belousov wrote: > tzload() allocates ~80KB for the local variables. The backtrace you provided > shows the nested call to tzload(), so there is total 160KB of the stack > space consumed. > By default, stack for the amd64 thread is 4MB, that should be plenty. This > is not the case for ezm3. Possibly, stunnel also reduces the size of the > thread stack. > Please, try the patch below. I did not tested it, only compiled. I see > that now tzload allocates only ~300 bytes on the stack. 80KB seems quite a lot indeed, good to bring it down. > diff --git a/contrib/tzcode/stdtime/localtime.c b/contrib/tzcode/stdtime/localtime.c > index 80b70ac..55d55e0 100644 > --- a/contrib/tzcode/stdtime/localtime.c > +++ b/contrib/tzcode/stdtime/localtime.c [snip] > @@ -406,16 +409,24 @@ register const int doextend; > ** to hold the longest file name string that the implementation > ** guarantees can be opened." > */ > - char fullname[FILENAME_MAX + 1]; > + char *fullname; > + > + fullname = malloc(FILENAME_MAX + 1); > + if (fullname == NULL) > + goto out; > > if (name[0] == ':') > ++name; > doaccess = name[0] == '/'; > if (!doaccess) { > - if ((p = TZDIR) == NULL) > + if ((p = TZDIR) == NULL) { > + free(fullname); > return -1; > - if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname) > + } > + if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname) { This sizeof is now the sizeof of a pointer. The comparison should be against FILENAME_MAX + 1 instead. Alternatively, the name could be created using asprintf(). -- Jilles Tjoelker