Fix strftime error handling - quark - quark web server | |
git clone git://git.suckless.org/quark | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit a982fa636704a436c3d1016b1f82806f607b7556 | |
parent bc9ba3e52e6ab56bb0761f95750c2c3be3012b52 | |
Author: robert <[email protected]> | |
Date: Fri, 8 Jul 2022 11:12:17 -0700 | |
Fix strftime error handling | |
Unlike snprintf, strftime buffer contents are undefined when it fails, | |
so make sure the buffer is null-terminated. To prevent garbage from | |
being printed out, we simply set the timestamp to the empty string, but | |
maybe setting it to "unknown time" or something similar would be better. | |
Either way, I don't think this can fail until year 10000, so it's not a | |
big deal. | |
Diffstat: | |
M connection.c | 3 ++- | |
1 file changed, 2 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/connection.c b/connection.c | |
@@ -31,7 +31,8 @@ connection_log(const struct connection *c) | |
if (!strftime(tstmp, sizeof(tstmp), "%Y-%m-%dT%H:%M:%SZ", | |
gmtime(&(time_t){time(NULL)}))) { | |
warn("strftime: Exceeded buffer capacity"); | |
- /* continue anyway (we accept the truncation) */ | |
+ tstmp[0] = '\0'; /* tstmp contents are undefined on failure */ | |
+ /* continue anyway */ | |
} | |
/* generate address-string */ |