about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tipideed/responses.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/tipideed/responses.c b/src/tipideed/responses.c
index 8f80b18..2f1df9d 100644
--- a/src/tipideed/responses.c
+++ b/src/tipideed/responses.c
@@ -42,6 +42,7 @@ void response_error (tipidee_rql const *rql, char const *docroot, unsigned int s
   tipidee_defaulttext dt ;
   char const *file = 0;
   size_t salen = g.sa.len ;
+
   if (sarealpath(&g.sa, docroot) == -1)
   {
     if (errno != ENOENT) strerr_diefu2sys(111, "realpath ", docroot) ;
@@ -54,6 +55,7 @@ void response_error (tipidee_rql const *rql, char const *docroot, unsigned int s
     file = tipidee_conf_get_errorfile(&g.conf, g.sa.s + salen + g.cwdlen + 1, status) ;
     g.sa.len = salen ;
   }
+
   if (!tipidee_util_defaulttext(status, &dt))
   {
     char fmt[UINT_FMT] ;
@@ -63,36 +65,39 @@ void response_error (tipidee_rql const *rql, char const *docroot, unsigned int s
 
   if (file)
   {
-    int fd ;
     if (sarealpath(&g.sa, file) == -1 || !stralloc_0(&g.sa))
-      strerr_diefu2sys(111, "realpath ", file) ;
-    if (strncmp(g.sa.s + salen, g.sa.s, g.cwdlen) || g.sa.s[salen + g.cwdlen] != '/')
-      strerr_dief4x(102, "layout error: ", "custom response file ", file, " points outside of the server's root") ;
-    fd = open_read(g.sa.s + salen + g.cwdlen + 1) ;
-    g.sa.len = salen ;
-    if (fd == -1) strerr_warnwu3sys("open ", "custom response file ", file) ;
+      strerr_warnwu3sys("realpath ", "custom response file ", file) ;
+    else if (strncmp(g.sa.s + salen, g.sa.s, g.cwdlen) || g.sa.s[salen + g.cwdlen] != '/')
+      strerr_warnw4x("layout error: ", "custom response file ", file, " points outside of the server's root") ;
     else
     {
-      struct stat st ;
-      if (fstat(fd, &st) == -1)
-      {
-        fd_close(fd) ;
-        strerr_warnwu3sys("stat ", "custom response file ", file) ;
-      }
-      else if (!S_ISREG(st.st_mode))
-      {
-        fd_close(fd) ;
-        strerr_warnw3x("custom response file ", file, " is not a regular file") ;
-      }
+      int fd = open_read(g.sa.s + salen + g.cwdlen + 1) ;
+      if (fd == -1) strerr_warnwu3sys("open ", "custom response file ", file) ;
       else
       {
-        tipidee_response_file_g(buffer_1, rql, status, dt.reason, &st, tipidee_conf_get_content_type(&g.conf, g.sa.s + salen + g.cwdlen + 1), g.rhdr, g.rhdrn, options) ;
-        tipidee_log_answer(g.logv, rql, status, st.st_size) ;
-        send_file(fd, st.st_size, g.sa.s + salen + g.cwdlen + 1) ;
-        fd_close(fd) ;
-        return ;
+        struct stat st ;
+        if (fstat(fd, &st) == -1)
+        {
+          fd_close(fd) ;
+          strerr_warnwu3sys("stat ", "custom response file ", file) ;
+        }
+        else if (!S_ISREG(st.st_mode))
+        {
+          fd_close(fd) ;
+          strerr_warnw3x("custom response file ", file, " is not a regular file") ;
+        }
+        else
+        {
+          tipidee_response_file_g(buffer_1, rql, status, dt.reason, &st, tipidee_conf_get_content_type(&g.conf, g.sa.s + salen + g.cwdlen + 1), g.rhdr, g.rhdrn, options) ;
+          tipidee_log_answer(g.logv, rql, status, st.st_size) ;
+          send_file(fd, st.st_size, g.sa.s + salen + g.cwdlen + 1) ;
+          fd_close(fd) ;
+          g.sa.len = salen ;
+          return ;
+        }
       }
     }
+    g.sa.len = salen ;
   }
 
   tipidee_response_error_nofile_g(buffer_1, rql, status, dt.reason, dt.text, g.rhdr, g.rhdrn, options & 1 || !g.cont) ;