Index | Thread | Search

From:
Jan Schreiber <jes@posteo.de>
Subject:
httpd: add missing NULL check
To:
tech@openbsd.org
Date:
Wed, 01 Apr 2026 18:47:24 +0000

Download raw body.

Thread
Hello,

if the kv_add call fails a gzipped response would be send without the 
gzip header.
With this change the fallback is to send an uncompressed response.

Jan

diff --git usr.sbin/httpd/server_file.c usr.sbin/httpd/server_file.c
index cdcc11cd800..d740675f28d 100644
--- usr.sbin/httpd/server_file.c
+++ usr.sbin/httpd/server_file.c
@@ -194,13 +194,16 @@ server_file_access(struct httpd *env, struct 
client *clt,
                                     S_ISREG(gzst.st_mode) &&
                                     timespeccmp(&gzst.st_mtim, &st.st_mtim,
                                     >=)) {
-  kv_add(&resp->http_headers,
-                                           "Content-Encoding", "gzip");
-                                       /* Use original file timestamp */
-                                       gzst.st_mtim = st.st_mtim;
-                                       st = gzst;
-                                       close(fd);
-                                       fd = gzfd;
+                                       if (kv_add(&resp->http_headers,
+                                           "Content-Encoding", "gzip") 
== NULL) {
+                                               close(gzfd);
+                                       } else {
+                                               /* Use original file 
timestamp */
+                                               gzst.st_mtim = st.st_mtim;
+                                               st = gzst;
+                                               close(fd);
+                                               fd = gzfd;
+                                       }
                                 } else {
                                         close(gzfd);
                                 }