about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-08-25 01:16:34 +0200
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-08-25 01:16:34 +0200
commitf4f0bc84f8b69c7b4538e56ec274f1a7342f6824 (patch)
treea3d01a03e00c67c3914fd73e3f7e8b479a3bf8e6
parente67ebf80e337f520011fbea4fa8f81cbd3dbe621 (diff)
fix(send_standard_headers): don't read from uninitialized memory
-rw-r--r--main.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/main.c b/main.c
index 21ab753..f5460ba 100644
--- a/main.c
+++ b/main.c
@@ -182,9 +182,14 @@ void send_standard_headers(int status, char content_type[]) {
     send_header("Content-type", content_type);
 
 #ifdef BLOG_CACHE_MAX_AGE
+    // TODO correct sized buffer, no snprintf
     char max_age[256];
     int result = snprintf(max_age, sizeof max_age, "max-age=%d", BLOG_CACHE_MAX_AGE);
-    if(result > 0 && max_age[sizeof max_age - 1] == '\0') {
+
+    // make sure there won't be a buffer overrun
+    max_age[sizeof max_age - 1] = '\0';
+
+    if(result > 0) {
         send_header("Cache-Control", max_age);
     }
 #endif