From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 30 04:10:30 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2B77E1065673 for ; Sun, 30 Nov 2008 04:10:30 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.delphij.net (delphij-pt.tunnel.tserv2.fmt.ipv6.he.net [IPv6:2001:470:1f03:2c9::2]) by mx1.freebsd.org (Postfix) with ESMTP id C72498FC0A for ; Sun, 30 Nov 2008 04:10:29 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.geekcn.org (tarsier.geekcn.org [211.166.10.233]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tarsier.delphij.net (Postfix) with ESMTPS id 115C328448 for ; Sun, 30 Nov 2008 12:10:28 +0800 (CST) Received: from localhost (tarsier.geekcn.org [211.166.10.233]) by tarsier.geekcn.org (Postfix) with ESMTP id 7F053ED981A; Sun, 30 Nov 2008 12:10:27 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([211.166.10.233]) by localhost (mail.geekcn.org [211.166.10.233]) (amavisd-new, port 10024) with ESMTP id Ug4bLpbM38SJ; Sun, 30 Nov 2008 12:10:22 +0800 (CST) Received: from delta.delphij.net (c-76-103-40-85.hsd1.ca.comcast.net [76.103.40.85]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id 39939EC75EA; Sun, 30 Nov 2008 12:10:20 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:cc:subject:references:in-reply-to: x-enigmail-version:openpgp:content-type:content-transfer-encoding; b=C4Djr9Ju8NHAhP4TCINFxVwMnCTT3XxegZ8YO/AY+ALt3OkSj97OmqQEusFgMKeNk DXlePo+HpvVV/IJ4Dc+sw== Message-ID: <4932122A.8070209@delphij.net> Date: Sat, 29 Nov 2008 20:10:18 -0800 From: Xin LI Organization: The Geek China Organization User-Agent: Thunderbird 2.0.0.18 (X11/20081123) MIME-Version: 1.0 To: Eitan Adler References: <49320FF7.4040901@gmail.com> In-Reply-To: <49320FF7.4040901@gmail.com> X-Enigmail-Version: 0.95.7 OpenPGP: id=18EDEBA0; url=http://www.delphij.net/delphij.asc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: change to ee.c X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Nov 2008 04:10:30 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Eitan, Eitan Adler wrote: > I changed this pursuant to a warning I got from gcc. > according to the man page "This avoids the race between testing for a > file's existence and opening it for use." > > Could someone on this list please tell me > a) If mkstemp is supposed to be used instead > b) if not, why not? > I tested this change and was able to spell check files (the function > which this changes). > > As an aside I got an unreproducible segfault 11 when I tried to > spellcheck an empty file. When I tried again I did not get the same > error. I have the ee.core file. > > --- ee.c.back 2008-11-29 22:52:28.000000000 -0500 > +++ ee.c 2008-11-29 22:52:35.000000000 -0500 > @@ -4386,7 +4386,7 @@ > return; > } > (void)sprintf(template, "/tmp/ee.XXXXXXXX"); > - name = mktemp(&template[0]); > + name = mkstemp(&template[0]); > fd = open(name, O_CREAT | O_EXCL | O_RDWR, 0600); > if (fd < 0) { > wmove(com_win, 0, 0); Tanks for interested in this but I'm afraid that your patch is incorrect. mkstemp returns a file descriptor rather than a string pointer, therefore, the subsequent open() would have undefined behavior. It looks like that we actually want fd = mkstemp() here. Note that we may want to bring vendor fixes before making any changes to reduce duplicated work... Cheers, - -- Xin LI http://www.delphij.net/ FreeBSD - The Power to Serve! -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkkyEioACgkQi+vbBBjt66Dg8QCgw5nCU0G1WnHYtVziiNMpawqh iPwAni7zA4yFnX9waNC0Hmj36rX6yrIG =iJ2c -----END PGP SIGNATURE-----