From: Jan Schreiber Subject: Re: httpd: add missing NULL check To: Theo Buehler Cc: tech@openbsd.org Date: Fri, 03 Apr 2026 11:27:47 +0000 On 4/2/26 15:52, Theo Buehler wrote: > On Wed, Apr 01, 2026 at 07:20:18PM +0000, Jan Schreiber wrote: >> Hi, >> >> last diff didn't conform to style(9), sorry >> I extracted the open for the gz file descriptor and it's now one level less >> indentation. > Unfortunately your inlined diffs don't apply since your mailer wraps > lines and messes up the whitespace by expanding tabs. Unless you can > figure out what's responsible for this, I think it would be preferable > if you sent them as an attachment. > Hi Theo, sorry for the mistake. I regenerated the patch and send it to myself as an attachement which seems to work in my testing. Thank you! Jan diff --git usr.sbin/httpd/server_file.c usr.sbin/httpd/server_file.c index cdcc11cd800..920847e1201 100644 --- usr.sbin/httpd/server_file.c +++ usr.sbin/httpd/server_file.c @@ -188,26 +188,32 @@ server_file_access(struct httpd *env, struct client *clt, return (500); } - if ((gzfd = open(gzpath, O_RDONLY)) != -1) { - /* .gz must be a file, and not older */ - if (fstat(gzfd, &gzst) != -1 && - S_ISREG(gzst.st_mode) && - timespeccmp(&gzst.st_mtim, &st.st_mtim, - >=)) { - kv_add(&resp->http_headers, - "Content-Encoding", "gzip"); + + gzfd = open(gzpath, O_RDONLY); + if (gzfd == -1) + goto done; + + /* .gz must be a file, and not older */ + if (fstat(gzfd, &gzst) != -1 && + S_ISREG(gzst.st_mode) && + timespeccmp(&gzst.st_mtim, &st.st_mtim, + >=)) { + 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); } + } else { + close(gzfd); } } } - +done: return (server_file_request(env, clt, media, fd, &st)); }