aboutsummaryrefslogtreecommitdiffstats
path: root/src/song_print.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-07-06 11:48:21 +0200
committerMax Kellermann <max@duempel.org>2009-07-06 11:48:21 +0200
commit17e3054399ba649b6e2c6fa8e7a946c286eafe77 (patch)
tree2d33e7e61631024cf330bf53e963d78412b3416f /src/song_print.c
parent09aadffe9bc14b42fb36342f1b133b8e15745b5c (diff)
downloadmpd-17e3054399ba649b6e2c6fa8e7a946c286eafe77.tar.gz
mpd-17e3054399ba649b6e2c6fa8e7a946c286eafe77.tar.xz
mpd-17e3054399ba649b6e2c6fa8e7a946c286eafe77.zip
song_print: check gmtime_r()'s return value
When song->mtime was not initialized properly, it was revealed that strftime() might crash when gmtime_r() returns NULL due to an invalid time_t input value.
Diffstat (limited to 'src/song_print.c')
-rw-r--r--src/song_print.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/song_print.c b/src/song_print.c
index 2efae9b89..2c4da6cb0 100644
--- a/src/song_print.c
+++ b/src/song_print.c
@@ -51,20 +51,24 @@ song_print_info(struct client *client, struct song *song)
song_print_url(client, song);
if (song->mtime > 0) {
- time_t t = song->mtime;
#ifndef G_OS_WIN32
struct tm tm;
#endif
- char timestamp[32];
+ const struct tm *tm2;
- strftime(timestamp, sizeof(timestamp), "%FT%TZ",
#ifdef G_OS_WIN32
- gmtime(&t)
+ tm2 = gmtime(&song->mtime);
#else
- gmtime_r(&t, &tm)
+ tm2 = gmtime_r(&song->mtime, &tm);
#endif
- );
- client_printf(client, "Last-Modified: %s\n", timestamp);
+
+ if (tm2 != NULL) {
+ char timestamp[32];
+
+ strftime(timestamp, sizeof(timestamp), "%FT%TZ", tm2);
+ client_printf(client, "Last-Modified: %s\n",
+ timestamp);
+ }
}
if (song->tag)