Commit 17e30543 authored by Max Kellermann's avatar Max Kellermann

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.
parent 09aadffe
...@@ -51,20 +51,24 @@ song_print_info(struct client *client, struct song *song) ...@@ -51,20 +51,24 @@ song_print_info(struct client *client, struct song *song)
song_print_url(client, song); song_print_url(client, song);
if (song->mtime > 0) { if (song->mtime > 0) {
time_t t = song->mtime;
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
struct tm tm; struct tm tm;
#endif #endif
char timestamp[32]; const struct tm *tm2;
strftime(timestamp, sizeof(timestamp), "%FT%TZ",
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
gmtime(&t) tm2 = gmtime(&song->mtime);
#else #else
gmtime_r(&t, &tm) tm2 = gmtime_r(&song->mtime, &tm);
#endif #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) if (song->tag)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment