summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config/headers.c2
-rw-r--r--src/libtipidee/tipidee_headers_parse.c13
-rw-r--r--src/tipideed/cgi.c2
-rw-r--r--src/tipideed/responses.c9
4 files changed, 16 insertions, 10 deletions
diff --git a/src/config/headers.c b/src/config/headers.c
index 4fcdf7d..077a733 100644
--- a/src/config/headers.c
+++ b/src/config/headers.c
@@ -25,6 +25,7 @@ static struct builtinheaders_s const builtinheaders[] =
{ .key = "Allow", .value = 0, .overridable = 0 },
{ .key = "Cache-Control", .value = "private", .overridable = 1 },
{ .key = "Connection", .value = 0, .overridable = 0 },
+ { .key = "Content-Length", .value = 0, .overridable = 0 },
{ .key = "Content-Security-Policy", .value = "default-src 'self'; style-src 'self' 'unsafe-inline';", .overridable = 1 },
{ .key = "Date", .value = 0, .overridable = 0 },
{ .key = "Referrer-Policy", .value = "no-referrer-when-downgrade", .overridable = 1 },
@@ -48,7 +49,6 @@ int header_allowed (char const *key)
{
static char const *const nope[] =
{
- "Content-Length",
"Content-Type",
"Location"
} ;
diff --git a/src/libtipidee/tipidee_headers_parse.c b/src/libtipidee/tipidee_headers_parse.c
index d906885..4881633 100644
--- a/src/libtipidee/tipidee_headers_parse.c
+++ b/src/libtipidee/tipidee_headers_parse.c
@@ -1,5 +1,6 @@
/* ISC license. */
+#include <sys/types.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
@@ -76,18 +77,18 @@ struct tainp_s
tain *stamp ;
} ;
-typedef int get1_func (buffer *, char *, struct tainp_s *) ;
+typedef ssize_t get1_func (buffer *, char *, struct tainp_s *) ;
typedef get1_func *get1_func_ref ;
-static int get1_timed (buffer *b, char *c, struct tainp_s *d)
+static ssize_t get1_timed (buffer *b, char *c, struct tainp_s *d)
{
return buffer_timed_get(b, c, 1, d->deadline, d->stamp) ;
}
-static int get1_notimed (buffer *b, char *c, struct tainp_s *data)
+static ssize_t get1_notimed (buffer *b, char *c, struct tainp_s *data)
{
(void)data ;
- return buffer_get(b, c, 1) == 1 ;
+ return buffer_get(b, c, 1) ;
}
static uint8_t cclass (char c)
@@ -121,8 +122,8 @@ static int tipidee_headers_parse_with (buffer *b, tipidee_headers *hdr, get1_fun
while (*state < 0x0a)
{
uint16_t c ;
- char cur ;
- if (!(*next)(b, &cur, data))
+ char cur = 0 ;
+ if ((*next)(b, &cur, data) < 0)
return errno == ETIMEDOUT ? 408 : error_isagain(errno) ? -2 : -1 ;
c = table[*state][cclass(cur)] ;
/*
diff --git a/src/tipideed/cgi.c b/src/tipideed/cgi.c
index 43fb98d..3319099 100644
--- a/src/tipideed/cgi.c
+++ b/src/tipideed/cgi.c
@@ -209,7 +209,7 @@ static inline int run_cgi (tipidee_rql const *rql, char const *docroot, char con
rstate = 1 ;
break ;
}
- case 400 : die502x(rql, 2, docroot, "invalid headers", " from cgi ", argv[0]) ;
+ case 400 : die502x(rql, 2, docroot, "invalid output", " from cgi ", argv[0]) ;
case 413 : die502x(rql, 2, docroot, hdr->n >= TIPIDEE_HEADERS_MAX ? "Too many headers" : "Too much header data", " from cgi ", argv[0]) ;
case 500 : die500x(rql, 101, docroot, "can't happen: ", "avltreen_insert failed", " in do_cgi") ;
default : die500x(rql, 101, docroot, "can't happen: ", "unknown tipidee_headers_parse return code", " in do_cgi") ;
diff --git a/src/tipideed/responses.c b/src/tipideed/responses.c
index f08f83c..ec58622 100644
--- a/src/tipideed/responses.c
+++ b/src/tipideed/responses.c
@@ -42,8 +42,12 @@ void response_error (tipidee_rql const *rql, char const *docroot, unsigned int s
tipidee_defaulttext dt ;
char const *file ;
size_t salen = g.sa.len ;
- if (sarealpath(&g.sa, docroot) == -1 || !stralloc_0(&g.sa))
- strerr_diefu2sys(111, "realpath ", docroot) ;
+ if (sarealpath(&g.sa, docroot) == -1)
+ {
+ if (errno != ENOENT) strerr_diefu2sys(111, "realpath ", docroot) ;
+ else goto nofile ;
+ }
+ if (!stralloc_0(&g.sa)) strerr_diefu1sys(111, "build response") ;
if (strncmp(g.sa.s + salen, g.sa.s, g.cwdlen) || g.sa.s[salen + g.cwdlen] != '/')
strerr_dief4x(102, "layout error: ", "docroot ", docroot, " points outside of the server's root") ;
file = tipidee_conf_get_errorfile(&g.conf, g.sa.s + salen + g.cwdlen + 1, status) ;
@@ -89,6 +93,7 @@ void response_error (tipidee_rql const *rql, char const *docroot, unsigned int s
}
}
+ nofile:
tipidee_response_error_nofile_g(buffer_1, rql, status, dt.reason, dt.text, g.rhdr, g.rhdrn, options & 1 || !g.cont) ;
tipidee_log_answer(g.logv, rql, status, 0) ;
tain_add_g(&deadline, &g.writetto) ;