diff options
author | Omar Polo <op@cvs.openbsd.org> | 2022-08-15 09:36:20 +0000 |
---|---|---|
committer | Omar Polo <op@cvs.openbsd.org> | 2022-08-15 09:36:20 +0000 |
commit | 90f8a313289eae11c545f3e6a0f5ea1ea14ea74b (patch) | |
tree | 5eac0975a88c18287612343389b321fab8c734d1 /usr.sbin/httpd | |
parent | 66b8a6ce9214054b5a2b2c78359836d097085ed5 (diff) |
plug a fd leak in read_errdoc if fstat fails or if the file is empty
tweak/ok tb@
Diffstat (limited to 'usr.sbin/httpd')
-rw-r--r-- | usr.sbin/httpd/server_http.c | 7 |
1 files 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 <mpfr@fn.de> @@ -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); |