From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#15015: Fix some minor races in hosts lacking mkostemp Date: Sun, 04 Aug 2013 10:01:42 -0700 Organization: UCLA Computer Science Department Message-ID: <51FE88F6.6000604@cs.ucla.edu> References: <51FCB3D5.7070704@cs.ucla.edu> <83mwozxj84.fsf@gnu.org> <83k3k3xi36.fsf@gnu.org> <51FD1663.6040501@cs.ucla.edu> <83d2puygbs.fsf@gnu.org> <51FD757C.401@cs.ucla.edu> <837gg1xxyf.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1375635743 21397 80.91.229.3 (4 Aug 2013 17:02:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Aug 2013 17:02:23 +0000 (UTC) Cc: 15015-done@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 04 19:02:25 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V61hH-0004Jx-KQ for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Aug 2013 19:02:23 +0200 Original-Received: from localhost ([::1]:40228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V61hH-0008EG-6S for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Aug 2013 13:02:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V61h8-00089J-1J for bug-gnu-emacs@gnu.org; Sun, 04 Aug 2013 13:02:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V61gz-0007Mn-Hy for bug-gnu-emacs@gnu.org; Sun, 04 Aug 2013 13:02:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V61gz-0007Mj-FK for bug-gnu-emacs@gnu.org; Sun, 04 Aug 2013 13:02:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1V61gx-00075q-Vk for bug-gnu-emacs@gnu.org; Sun, 04 Aug 2013 13:02:04 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 04 Aug 2013 17:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 15015 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 15015@debbugs.gnu.org, eggert@cs.ucla.edu, eggert@cs.ucla.edu Original-Received: via spool by 15015-done@debbugs.gnu.org id=D15015.137563571527243 (code D ref 15015); Sun, 04 Aug 2013 17:02:02 +0000 Original-Received: (at 15015-done) by debbugs.gnu.org; 4 Aug 2013 17:01:55 +0000 Original-Received: from localhost ([127.0.0.1]:39855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1V61gn-00075K-QZ for submit@debbugs.gnu.org; Sun, 04 Aug 2013 13:01:54 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:52646) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1V61gk-000753-PA for 15015-done@debbugs.gnu.org; Sun, 04 Aug 2013 13:01:52 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id E08BFA60035; Sun, 4 Aug 2013 10:01:44 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kkY9HHqxx7Sx; Sun, 4 Aug 2013 10:01:42 -0700 (PDT) Original-Received: from [192.168.1.9] (pool-71-108-49-126.lsanca.fios.verizon.net [71.108.49.126]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 99971A60032; Sun, 4 Aug 2013 10:01:42 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 In-Reply-To: <837gg1xxyf.fsf@gnu.org> X-Enigmail-Version: 1.5.2 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:76949 Archived-At: On 08/04/2013 08:44 AM, Eli Zaretskii wrote: > So I went ahead and implemented mkostemp for MS-Windows (trunk > revision 113687). I also removed sys_mktemp, as it is no longer > needed. Thanks, that should do it on the Microsoft side. I installed the patch and am marking this done. The patch I installed also included the following additional simplification: === modified file 'ChangeLog' --- ChangeLog 2013-08-04 01:23:59 +0000 +++ ChangeLog 2013-08-04 16:52:55 +0000 @@ -2,6 +2,9 @@ Fix some minor races in hosts lacking mkostemp (Bug#15015). Gnulib's emulation of mkostemp doesn't have races that Emacs's does. + * configure.ac (mkostemp): Remove check for this function; + gnulib does the check now. + (mkstemp): Remove check for this no-longer-used function. * lib/mkostemp.c, lib/secure_getenv.c, lib/tempname.c, lib/tempname.h: * m4/mkostemp.m4, m4/secure_getenv.m4, m4/tempname.m4: New files, copied from Gnulib. === modified file 'configure.ac' --- configure.ac 2013-07-27 01:18:21 +0000 +++ configure.ac 2013-08-04 16:52:25 +0000 @@ -3277,7 +3277,7 @@ getrlimit setrlimit shutdown getaddrinfo \ strsignal setitimer \ sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ -gai_strerror mkostemp mkstemp getline getdelim sync \ +gai_strerror getline getdelim sync \ difftime posix_memalign \ getpwent endpwent getgrent endgrent \ touchlock \ === modified file 'lib-src/ChangeLog' --- lib-src/ChangeLog 2013-07-10 23:23:57 +0000 +++ lib-src/ChangeLog 2013-08-04 16:48:02 +0000 @@ -1,3 +1,12 @@ +2013-08-04 Paul Eggert + + Fix some minor races in hosts lacking mkostemp (Bug#15015). + * movemail.c (main): + * update-game-score.c (write_scores): + Use mkostemp (which now works on all platforms, due to changes + in the portability layer) rather than mktemp (which has a race) + or mkstemp (which we no longer bother with). + 2013-07-10 Paul Eggert Port to C89. === modified file 'lib-src/movemail.c' --- lib-src/movemail.c 2013-03-13 18:42:22 +0000 +++ lib-src/movemail.c 2013-08-04 16:35:45 +0000 @@ -304,24 +304,13 @@ memcpy (tempname, inname, inname_dirlen); strcpy (tempname + inname_dirlen, "EXXXXXX"); -#ifdef HAVE_MKSTEMP - desc = mkstemp (tempname); -#else - mktemp (tempname); - if (!*tempname) - desc = -1; - else - { - unlink (tempname); - desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0600); - } -#endif + desc = mkostemp (tempname, 0); if (desc < 0) { - int mkstemp_errno = errno; + int mkostemp_errno = errno; error ("error while creating what would become the lock file", 0, 0); - errno = mkstemp_errno; + errno = mkostemp_errno; pfatal_with_name (tempname); } close (desc); === modified file 'lib-src/update-game-score.c' --- lib-src/update-game-score.c 2013-03-30 17:00:51 +0000 +++ lib-src/update-game-score.c 2013-08-04 16:28:47 +0000 @@ -383,6 +383,7 @@ static int write_scores (const char *filename, const struct score_entry *scores, int count) { + int fd; FILE *f; int i; char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1); @@ -390,12 +391,11 @@ return -1; strcpy (tempfile, filename); strcat (tempfile, ".tempXXXXXX"); -#ifdef HAVE_MKSTEMP - if (mkstemp (tempfile) < 0 -#else - if (mktemp (tempfile) != tempfile -#endif - || !(f = fopen (tempfile, "w"))) + fd = mkostemp (tempfile, 0); + if (fd < 0) + return -1; + f = fdopen (fd, "w"); + if (! f) return -1; for (i = 0; i < count; i++) if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username,