Stop logging misleading errors when custom generic error pages are in use.
authorclaudio <claudio@openbsd.org>
Tue, 13 Feb 2024 14:00:24 +0000 (14:00 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 13 Feb 2024 14:00:24 +0000 (14:00 +0000)
Only call the open(2) log_warn for errnos that are not ENOENT. Since
that is an error worth logging.

Based on a diff from Carsten Reith (carsten.reith t-online.de)
OK florian@ deraadt@

usr.sbin/httpd/server_http.c

index 08deda7..0a814e7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server_http.c,v 1.153 2022/09/21 05:55:18 yasuoka Exp $       */
+/*     $OpenBSD: server_http.c,v 1.154 2024/02/13 14:00:24 claudio Exp $       */
 
 /*
  * Copyright (c) 2020 Matthias Pressfreund <mpfr@fn.de>
@@ -1762,13 +1762,14 @@ read_errdoc(const char *root, const char *file)
        struct stat      sb;
        char            *path;
        int              fd;
-       char            *ret = NULL;
+       char            *ret;
 
        if (asprintf(&path, "%s/%s.html", root, file) == -1)
                fatal("asprintf");
        if ((fd = open(path, O_RDONLY)) == -1) {
                free(path);
-               log_warn("%s: open", __func__);
+               if (errno != ENOENT)
+                       log_warn("%s: open", __func__);
                return (NULL);
        }
        free(path);
@@ -1788,8 +1789,7 @@ read_errdoc(const char *root, const char *file)
                log_warn("%s: read", __func__);
                close(fd);
                free(ret);
-               ret = NULL;
-               return (ret);
+               return (NULL);
        }
        close(fd);