Index | Thread | Search

From:
"Carsten Reith" <carsten.reith@t-online.de>
Subject:
Re: diff httpd: avoid misleading syslog warnings
To:
Matthias Pressfreund <mpfr@fn.de>, tech@openbsd.org
Date:
Tue, 13 Feb 2024 14:56:41 +0100

Download raw body.

Thread
On Tue, Feb 13, 2024 at 02:34:32PM +0100, Matthias Pressfreund wrote:
> The diff introduces a memory leak as it does not call free(path)
> before returning. What about just removing the log_warn?

Ooops, you are right.

I would like to keep the log_warn, because it can be perfectly justified
(see the other two replies.)

I added the free to the diff.


Index: server_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.153
diff -u -p -u -p -r1.153 server_http.c
--- server_http.c	21 Sep 2022 05:55:18 -0000	1.153
+++ server_http.c	13 Feb 2024 13:55:29 -0000
@@ -1766,6 +1766,10 @@ read_errdoc(const char *root, const char
 
 	if (asprintf(&path, "%s/%s.html", root, file) == -1)
 		fatal("asprintf");
+	if (access(path, R_OK) == -1) {
+		free(path);
+		return (NULL);
+	}
 	if ((fd = open(path, O_RDONLY)) == -1) {
 		free(path);
 		log_warn("%s: open", __func__);