Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Nov 2008 20:10:18 -0800
From:      Xin LI <delphij@delphij.net>
To:        Eitan Adler <eitanadlerlist@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: change to ee.c
Message-ID:  <4932122A.8070209@delphij.net>
In-Reply-To: <49320FF7.4040901@gmail.com>
References:  <49320FF7.4040901@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
-----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 <delphij@delphij.net>	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-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4932122A.8070209>