diff options
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/ChangeLog | 9 | ||||
| -rw-r--r-- | lib-src/movemail.c | 17 | ||||
| -rw-r--r-- | lib-src/update-game-score.c | 12 |
3 files changed, 18 insertions, 20 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index f41c23df5d2..2cfe46f5352 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2013-08-04 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Fix some minor races in hosts lacking mkostemp (Bug#15015). | ||
| 4 | * movemail.c (main): | ||
| 5 | * update-game-score.c (write_scores): | ||
| 6 | Use mkostemp (which now works on all platforms, due to changes | ||
| 7 | in the portability layer) rather than mktemp (which has a race) | ||
| 8 | or mkstemp (which we no longer bother with). | ||
| 9 | |||
| 1 | 2013-07-10 Paul Eggert <eggert@cs.ucla.edu> | 10 | 2013-07-10 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 11 | ||
| 3 | Port to C89. | 12 | Port to C89. |
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 81ac8aa187c..9434782cb17 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -304,24 +304,13 @@ main (int argc, char **argv) | |||
| 304 | 304 | ||
| 305 | memcpy (tempname, inname, inname_dirlen); | 305 | memcpy (tempname, inname, inname_dirlen); |
| 306 | strcpy (tempname + inname_dirlen, "EXXXXXX"); | 306 | strcpy (tempname + inname_dirlen, "EXXXXXX"); |
| 307 | #ifdef HAVE_MKSTEMP | 307 | desc = mkostemp (tempname, 0); |
| 308 | desc = mkstemp (tempname); | ||
| 309 | #else | ||
| 310 | mktemp (tempname); | ||
| 311 | if (!*tempname) | ||
| 312 | desc = -1; | ||
| 313 | else | ||
| 314 | { | ||
| 315 | unlink (tempname); | ||
| 316 | desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0600); | ||
| 317 | } | ||
| 318 | #endif | ||
| 319 | if (desc < 0) | 308 | if (desc < 0) |
| 320 | { | 309 | { |
| 321 | int mkstemp_errno = errno; | 310 | int mkostemp_errno = errno; |
| 322 | error ("error while creating what would become the lock file", | 311 | error ("error while creating what would become the lock file", |
| 323 | 0, 0); | 312 | 0, 0); |
| 324 | errno = mkstemp_errno; | 313 | errno = mkostemp_errno; |
| 325 | pfatal_with_name (tempname); | 314 | pfatal_with_name (tempname); |
| 326 | } | 315 | } |
| 327 | close (desc); | 316 | close (desc); |
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index ec8b4317770..1699e305c8d 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c | |||
| @@ -383,6 +383,7 @@ sort_scores (struct score_entry *scores, int count, int reverse) | |||
| 383 | static int | 383 | static int |
| 384 | write_scores (const char *filename, const struct score_entry *scores, int count) | 384 | write_scores (const char *filename, const struct score_entry *scores, int count) |
| 385 | { | 385 | { |
| 386 | int fd; | ||
| 386 | FILE *f; | 387 | FILE *f; |
| 387 | int i; | 388 | int i; |
| 388 | char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1); | 389 | char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1); |
| @@ -390,12 +391,11 @@ write_scores (const char *filename, const struct score_entry *scores, int count) | |||
| 390 | return -1; | 391 | return -1; |
| 391 | strcpy (tempfile, filename); | 392 | strcpy (tempfile, filename); |
| 392 | strcat (tempfile, ".tempXXXXXX"); | 393 | strcat (tempfile, ".tempXXXXXX"); |
| 393 | #ifdef HAVE_MKSTEMP | 394 | fd = mkostemp (tempfile, 0); |
| 394 | if (mkstemp (tempfile) < 0 | 395 | if (fd < 0) |
| 395 | #else | 396 | return -1; |
| 396 | if (mktemp (tempfile) != tempfile | 397 | f = fdopen (fd, "w"); |
| 397 | #endif | 398 | if (! f) |
| 398 | || !(f = fopen (tempfile, "w"))) | ||
| 399 | return -1; | 399 | return -1; |
| 400 | for (i = 0; i < count; i++) | 400 | for (i = 0; i < count; i++) |
| 401 | if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username, | 401 | if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username, |