summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe xhr <xhr@giessen.ccc.de>2021-08-26 12:34:54 +0200
committerthe xhr <xhr@giessen.ccc.de>2021-08-26 12:34:54 +0200
commit2c012a4d668fb7b9750efa29780f6ca3a9ef1598 (patch)
treebc41a41cffc8bcfc77fa009914589211034257a0
parent56b35e42d570e4505081c2f1a9f8bc94704c7045 (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.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/log.c b/log.c
index 6e07ccb..54a7c48 100644
--- a/log.c
+++ b/log.c
@@ -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);
generated by cgit on OpenBSD