diff options
author | the xhr <xhr@giessen.ccc.de> | 2021-08-26 12:34:54 +0200 |
---|---|---|
committer | the xhr <xhr@giessen.ccc.de> | 2021-08-26 12:34:54 +0200 |
commit | 2c012a4d668fb7b9750efa29780f6ca3a9ef1598 (patch) | |
tree | bc41a41cffc8bcfc77fa009914589211034257a0 | |
parent | 56b35e42d570e4505081c2f1a9f8bc94704c7045 (diff) |
Check the return value of strftime()
While OpenBSD guarantees NUL termination on overflow, other platforms
don't and thus the contents of the array are undefined.
-rw-r--r-- | log.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -243,7 +243,10 @@ log_access(const struct client_connection *cc, const char *fmt, ...) t = time(NULL); tm = *localtime(&t); - strftime(tmstr, sizeof(tmstr), "%d/%b/%Y:%H:%M:%S %Z", &tm); + if (strftime(tmstr, sizeof(tmstr), "%d/%b/%Y:%H:%M:%S %Z", &tm) == 0) { + log_warn("strftime couldn't save time string"); + return; + } user_log(0, "%s - - [%s] %s", cc->client_addr, tmstr, fmt); } @@ -257,7 +260,10 @@ log_error(const struct client_connection *cc, const char *fmt, ...) t = time(NULL); tm = *localtime(&t); - strftime(tmstr, sizeof(tmstr), "%d/%b/%Y:%H:%M:%S %Z", &tm); + if (strftime(tmstr, sizeof(tmstr), "%d/%b/%Y:%H:%M:%S %Z", &tm) == 0) { + log_warn("strftime couldn't save time string"); + return; + } user_log(1, "[%s] [error] [client %s] %s", tmstr, cc->client_addr, fmt); |