diff options
| author | Paul Eggert | 2013-08-04 09:56:56 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-08-04 09:56:56 -0700 |
| commit | e0fdb6943066032db294720915c3bd644bf2bcd1 (patch) | |
| tree | 0aa420b81dc0187e2efec3ff4fe3cf046ad1c598 /src | |
| parent | 484ab23924d39b3e26d54074fd659633e1660ef4 (diff) | |
| download | emacs-e0fdb6943066032db294720915c3bd644bf2bcd1.tar.gz emacs-e0fdb6943066032db294720915c3bd644bf2bcd1.zip | |
Fix some minor races in hosts lacking mkostemp.
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.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* admin/merge-gnulib (GNULIB_MODULES): Add mkostemp.
* lib-src/movemail.c (main):
* lib-src/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).
* src/callproc.c (create_temp_file):
* src/filelock.c (create_lock_file):
Assume mkostemp, since it's now provided by Gnulib.
Fixes: debbugs:15015
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/callproc.c | 14 | ||||
| -rw-r--r-- | src/filelock.c | 18 |
3 files changed, 10 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c29c4c8da59..f8f2fa47089 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2013-08-04 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Fix some minor races in hosts lacking mkostemp (Bug#15015). | ||
| 4 | * callproc.c (create_temp_file): | ||
| 5 | * filelock.c (create_lock_file): | ||
| 6 | Assume mkostemp, since it's now provided by Gnulib. | ||
| 7 | |||
| 1 | 2013-08-04 Eli Zaretskii <eliz@gnu.org> | 8 | 2013-08-04 Eli Zaretskii <eliz@gnu.org> |
| 2 | 9 | ||
| 3 | * w32.c (mkostemp): New function. | 10 | * w32.c (mkostemp): New function. |
diff --git a/src/callproc.c b/src/callproc.c index 450fc57f929..54bc5cd9dc0 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -1009,23 +1009,11 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args) | |||
| 1009 | tempfile = SSDATA (filename_string); | 1009 | tempfile = SSDATA (filename_string); |
| 1010 | 1010 | ||
| 1011 | { | 1011 | { |
| 1012 | int fd; | 1012 | int fd = mkostemp (tempfile, O_CLOEXEC); |
| 1013 | |||
| 1014 | #ifdef HAVE_MKOSTEMP | ||
| 1015 | fd = mkostemp (tempfile, O_CLOEXEC); | ||
| 1016 | #elif defined HAVE_MKSTEMP | ||
| 1017 | fd = mkstemp (tempfile); | ||
| 1018 | #else | ||
| 1019 | errno = EEXIST; | ||
| 1020 | mktemp (tempfile); | ||
| 1021 | fd = *tempfile ? 0 : -1; | ||
| 1022 | #endif | ||
| 1023 | if (fd < 0) | 1013 | if (fd < 0) |
| 1024 | report_file_error ("Failed to open temporary file using pattern", | 1014 | report_file_error ("Failed to open temporary file using pattern", |
| 1025 | pattern); | 1015 | pattern); |
| 1026 | #if defined HAVE_MKOSTEMP || defined HAVE_MKSTEMP | ||
| 1027 | emacs_close (fd); | 1016 | emacs_close (fd); |
| 1028 | #endif | ||
| 1029 | } | 1017 | } |
| 1030 | 1018 | ||
| 1031 | record_unwind_protect (delete_temp_file, filename_string); | 1019 | record_unwind_protect (delete_temp_file, filename_string); |
diff --git a/src/filelock.c b/src/filelock.c index b9c991e4baf..0f31b7d4deb 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -411,28 +411,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force) | |||
| 411 | memcpy (nonce, lfname, lfdirlen); | 411 | memcpy (nonce, lfname, lfdirlen); |
| 412 | strcpy (nonce + lfdirlen, nonce_base); | 412 | strcpy (nonce + lfdirlen, nonce_base); |
| 413 | 413 | ||
| 414 | #if HAVE_MKOSTEMP | ||
| 415 | /* Prefer mkostemp to mkstemp, as it avoids a window where FD is | ||
| 416 | temporarily open without close-on-exec. */ | ||
| 417 | fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); | 414 | fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); |
| 418 | #elif HAVE_MKSTEMP | ||
| 419 | /* Prefer mkstemp to mktemp, as it avoids a race between | ||
| 420 | mktemp and emacs_open. */ | ||
| 421 | fd = mkstemp (nonce); | ||
| 422 | #else | ||
| 423 | mktemp (nonce); | ||
| 424 | fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, | ||
| 425 | S_IRUSR | S_IWUSR); | ||
| 426 | #endif | ||
| 427 | |||
| 428 | if (fd < 0) | 415 | if (fd < 0) |
| 429 | err = errno; | 416 | err = errno; |
| 430 | else | 417 | else |
| 431 | { | 418 | { |
| 432 | ptrdiff_t lock_info_len; | 419 | ptrdiff_t lock_info_len; |
| 433 | #if ! (HAVE_MKOSTEMP && O_CLOEXEC) | 420 | if (! O_CLOEXEC) |
| 434 | fcntl (fd, F_SETFD, FD_CLOEXEC); | 421 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
| 435 | #endif | ||
| 436 | lock_info_len = strlen (lock_info_str); | 422 | lock_info_len = strlen (lock_info_str); |
| 437 | err = 0; | 423 | err = 0; |
| 438 | /* Use 'write', not 'emacs_write', as garbage collection | 424 | /* Use 'write', not 'emacs_write', as garbage collection |