diff options
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | configure.ac | 1 | ||||
| -rw-r--r-- | lib-src/ChangeLog | 12 | ||||
| -rw-r--r-- | lib-src/update-game-score.c | 20 |
4 files changed, 25 insertions, 13 deletions
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-01-22 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Fix miscellaneous update-game-score bugs. | ||
| 4 | * configure.ac (difftime): Remove. | ||
| 5 | |||
| 1 | 2014-01-20 Paul Eggert <eggert@cs.ucla.edu> | 6 | 2014-01-20 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 7 | ||
| 3 | Merge from gnulib, incorporating: | 8 | Merge from gnulib, incorporating: |
diff --git a/configure.ac b/configure.ac index 8443d168c7d..626dcb1c3ea 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -3468,7 +3468,6 @@ getrlimit setrlimit shutdown getaddrinfo \ | |||
| 3468 | strsignal setitimer \ | 3468 | strsignal setitimer \ |
| 3469 | sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ | 3469 | sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ |
| 3470 | gai_strerror getline getdelim sync \ | 3470 | gai_strerror getline getdelim sync \ |
| 3471 | difftime \ | ||
| 3472 | getpwent endpwent getgrent endgrent \ | 3471 | getpwent endpwent getgrent endgrent \ |
| 3473 | touchlock \ | 3472 | touchlock \ |
| 3474 | cfmakeraw cfsetspeed copysign __executable_start log2) | 3473 | cfmakeraw cfsetspeed copysign __executable_start log2) |
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index a354f832f32..0d06a926bae 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2014-01-22 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Fix miscellaneous update-game-score bugs. | ||
| 4 | * update-game-score.c (difftime) [!HAVE_DIFFTIME]: Remove. | ||
| 5 | (read_score) [HAVE_GETDELIM]: Don't access uninitialized storage. | ||
| 6 | (read_scores, write_scores): Check for fclose failure. | ||
| 7 | (write_scores): Use fchmod, not chmod, to avoid a race. | ||
| 8 | (lock_file): Fix test for out-of-date lock file; it was reversed. | ||
| 9 | Use ordinary subtraction rather than difftime; since we're already | ||
| 10 | assuming POSIX we don't need to worry about the possibility of | ||
| 11 | time_t being a magic cookie. | ||
| 12 | |||
| 1 | 2014-01-19 Paul Eggert <eggert@cs.ucla.edu> | 13 | 2014-01-19 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 14 | ||
| 3 | update-game-score fixes for -m and integer overflow (Bug#16428) | 15 | update-game-score fixes for -m and integer overflow (Bug#16428) |
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 916a351432d..d9218ff67b7 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c | |||
| @@ -59,11 +59,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 59 | #define MAX_ATTEMPTS 5 | 59 | #define MAX_ATTEMPTS 5 |
| 60 | #define MAX_DATA_LEN 1024 | 60 | #define MAX_DATA_LEN 1024 |
| 61 | 61 | ||
| 62 | #ifndef HAVE_DIFFTIME | ||
| 63 | /* OK on POSIX (time_t is arithmetic type) modulo overflow in subtraction. */ | ||
| 64 | #define difftime(t1, t0) (double)((t1) - (t0)) | ||
| 65 | #endif | ||
| 66 | |||
| 67 | static _Noreturn void | 62 | static _Noreturn void |
| 68 | usage (int err) | 63 | usage (int err) |
| 69 | { | 64 | { |
| @@ -275,6 +270,7 @@ read_score (FILE *f, struct score_entry *score) | |||
| 275 | #ifdef HAVE_GETDELIM | 270 | #ifdef HAVE_GETDELIM |
| 276 | { | 271 | { |
| 277 | size_t count = 0; | 272 | size_t count = 0; |
| 273 | score->username = 0; | ||
| 278 | if (getdelim (&score->username, &count, ' ', f) < 1 | 274 | if (getdelim (&score->username, &count, ' ', f) < 1 |
| 279 | || score->username == NULL) | 275 | || score->username == NULL) |
| 280 | return -1; | 276 | return -1; |
| @@ -371,14 +367,13 @@ read_scores (const char *filename, struct score_entry **scores, | |||
| 371 | while ((readval = read_score (f, &entry)) == 0) | 367 | while ((readval = read_score (f, &entry)) == 0) |
| 372 | if (push_score (&ret, &scorecount, &cursize, &entry) < 0) | 368 | if (push_score (&ret, &scorecount, &cursize, &entry) < 0) |
| 373 | return -1; | 369 | return -1; |
| 374 | if (readval > 0) | 370 | if (readval > 0 && fclose (f) == 0) |
| 375 | { | 371 | { |
| 376 | *count = scorecount; | 372 | *count = scorecount; |
| 377 | *alloc = cursize; | 373 | *alloc = cursize; |
| 378 | *scores = ret; | 374 | *scores = ret; |
| 379 | retval = 0; | 375 | retval = 0; |
| 380 | } | 376 | } |
| 381 | fclose (f); | ||
| 382 | return retval; | 377 | return retval; |
| 383 | } | 378 | } |
| 384 | 379 | ||
| @@ -448,6 +443,8 @@ write_scores (const char *filename, const struct score_entry *scores, | |||
| 448 | fd = mkostemp (tempfile, 0); | 443 | fd = mkostemp (tempfile, 0); |
| 449 | if (fd < 0) | 444 | if (fd < 0) |
| 450 | return -1; | 445 | return -1; |
| 446 | if (fchmod (fd, 0644) != 0) | ||
| 447 | return -1; | ||
| 451 | f = fdopen (fd, "w"); | 448 | f = fdopen (fd, "w"); |
| 452 | if (! f) | 449 | if (! f) |
| 453 | return -1; | 450 | return -1; |
| @@ -456,10 +453,9 @@ write_scores (const char *filename, const struct score_entry *scores, | |||
| 456 | scores[i].score, scores[i].username, scores[i].data) | 453 | scores[i].score, scores[i].username, scores[i].data) |
| 457 | < 0) | 454 | < 0) |
| 458 | return -1; | 455 | return -1; |
| 459 | fclose (f); | 456 | if (fclose (f) != 0) |
| 460 | if (rename (tempfile, filename) < 0) | ||
| 461 | return -1; | 457 | return -1; |
| 462 | if (chmod (filename, 0644) < 0) | 458 | if (rename (tempfile, filename) != 0) |
| 463 | return -1; | 459 | return -1; |
| 464 | return 0; | 460 | return 0; |
| 465 | } | 461 | } |
| @@ -479,9 +475,9 @@ lock_file (const char *filename, void **state) | |||
| 479 | *state = lockpath; | 475 | *state = lockpath; |
| 480 | trylock: | 476 | trylock: |
| 481 | attempts++; | 477 | attempts++; |
| 482 | /* If the lock is over an hour old, delete it. */ | 478 | /* If the lock is over an hour old, delete it. */ |
| 483 | if (stat (lockpath, &buf) == 0 | 479 | if (stat (lockpath, &buf) == 0 |
| 484 | && (difftime (buf.st_ctime, time (NULL) > 60*60))) | 480 | && 60 * 60 < time (0) - buf.st_ctime) |
| 485 | unlink (lockpath); | 481 | unlink (lockpath); |
| 486 | fd = open (lockpath, O_CREAT | O_EXCL, 0600); | 482 | fd = open (lockpath, O_CREAT | O_EXCL, 0600); |
| 487 | if (fd < 0) | 483 | if (fd < 0) |