From dabb292335db8bf08f01d618bdfe739077955391 Mon Sep 17 00:00:00 2001 From: op Date: Mon, 15 Aug 2022 09:36:19 +0000 Subject: [PATCH] plug a fd leak in read_errdoc if fstat fails or if the file is empty tweak/ok tb@ --- usr.sbin/httpd/server_http.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c index 63c91e8d075..776aa040a05 100644 --- a/usr.sbin/httpd/server_http.c +++ b/usr.sbin/httpd/server_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server_http.c,v 1.150 2022/03/02 11:10:43 florian Exp $ */ +/* $OpenBSD: server_http.c,v 1.151 2022/08/15 09:36:19 op Exp $ */ /* * Copyright (c) 2020 Matthias Pressfreund @@ -1777,13 +1777,16 @@ read_errdoc(const char *root, const char *file) free(path); if (fstat(fd, &sb) < 0) { log_warn("%s: stat", __func__); + close(fd); return (NULL); } if ((ret = calloc(1, sb.st_size + 1)) == NULL) fatal("calloc"); - if (sb.st_size == 0) + if (sb.st_size == 0) { + close(fd); return (ret); + } if (read(fd, ret, sb.st_size) != sb.st_size) { log_warn("%s: read", __func__); close(fd); -- 2.20.1