Feature #2438 ยป lighttpd_1.4.29_reject_417_regexp.patch
lighttpd-1.4.29/src/base.h 2011-08-19 11:34:43.785881549 +0200 | ||
---|---|---|
#endif
|
||
} stat_cache_engine;
|
||
unsigned short enable_cores;
|
||
unsigned short reject_expect_100_with_417;
|
||
buffer *reject_expect_100_with_417;
|
||
} server_config;
|
||
typedef struct {
|
lighttpd-1.4.29/src/configfile.c 2011-08-19 12:03:34.870531924 +0200 | ||
---|---|---|
{ "etag.use-inode", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */
|
||
{ "etag.use-mtime", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */
|
||
{ "etag.use-size", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 51 */
|
||
{ "server.reject-expect-100-with-417", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 52 */
|
||
{ "server.reject-expect-100-with-417", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 52 */
|
||
{ "debug.log-timeouts", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 53 */
|
||
{ "server.defer-accept", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 54 */
|
||
{ "server.breakagelog", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 55 */
|
||
... | ... | |
cv[10].destination = srv->srvconf.event_handler;
|
||
cv[11].destination = srv->srvconf.pid_file;
|
||
cv[52].destination = srv->srvconf.reject_expect_100_with_417;
|
||
cv[13].destination = &(srv->srvconf.max_worker);
|
||
cv[23].destination = &(srv->srvconf.max_fds);
|
||
cv[37].destination = &(srv->srvconf.log_request_header_on_error);
|
||
... | ... | |
cv[43].destination = &(srv->srvconf.max_conns);
|
||
cv[12].destination = &(srv->srvconf.max_request_size);
|
||
cv[52].destination = &(srv->srvconf.reject_expect_100_with_417);
|
||
cv[55].destination = srv->srvconf.breakagelog_file;
|
||
srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
|
lighttpd-1.4.29/src/request.c 2011-08-19 11:36:02.430095621 +0200 | ||
---|---|---|
array_insert_unique(con->request.headers, (data_unset *)ds);
|
||
return 0;
|
||
}
|
||
#ifdef HAVE_PCRE_H
|
||
} else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Expect")))) {
|
||
/* HTTP 2616 8.2.3
|
||
* Expect: 100-continue
|
||
... | ... | |
* header
|
||
*
|
||
*/
|
||
if (srv->srvconf.reject_expect_100_with_417 && 0 == buffer_caseless_compare(CONST_BUF_LEN(ds->value), CONST_STR_LEN("100-continue"))) {
|
||
con->http_status = 417;
|
||
con->keep_alive = 0;
|
||
array_insert_unique(con->request.headers, (data_unset *)ds);
|
||
return 0;
|
||
if (0 == buffer_caseless_compare(CONST_BUF_LEN(ds->value), CONST_STR_LEN("100-continue"))) {
|
||
// Check whether the URI matches the regexp
|
||
const char *error;
|
||
int erroffset;
|
||
int negate = *(srv->srvconf.reject_expect_100_with_417->ptr) == '!';
|
||
const char *expr =
|
||
(srv->srvconf.reject_expect_100_with_417->ptr) + (negate ? 1 : 0);
|
||
pcre *regexp = pcre_compile(
|
||
expr,
|
||
0,
|
||
&error,
|
||
&erroffset,
|
||
NULL);
|
||
if (regexp)
|
||
{
|
||
int matched = pcre_exec(
|
||
regexp,
|
||
NULL,
|
||
con->request.uri->ptr,
|
||
con->request.uri->used,
|
||
0,
|
||
0,
|
||
NULL,
|
||
0
|
||
);
|
||
pcre_free(regexp);
|
||
if ((matched >= 0) != negate)
|
||
{
|
||
con->http_status = 417;
|
||
con->keep_alive = 0;
|
||
array_insert_unique(con->request.headers, (data_unset *)ds);
|
||
return 0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
log_error_write(srv, __FILE__, __LINE__, "s",
|
||
"Error while compiling regexp for 417 error!");
|
||
}
|
||
}
|
||
#endif
|
||
} else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Host")))) {
|
||
if (reqline_host) {
|
||
/* ignore all host: headers as we got the host in the request line */
|
lighttpd-1.4.29/src/server.c 2011-08-19 12:04:14.512871495 +0200 | ||
---|---|---|
CLEAN(srvconf.bindhost);
|
||
CLEAN(srvconf.event_handler);
|
||
CLEAN(srvconf.pid_file);
|
||
srv->srvconf.reject_expect_100_with_417 = buffer_init_string(".*");
|
||
CLEAN(tmp_chunk_len);
|
||
#undef CLEAN
|
||
... | ... | |
srv->srvconf.modules_dir = buffer_init_string(LIBRARY_DIR);
|
||
srv->srvconf.network_backend = buffer_init();
|
||
srv->srvconf.upload_tempdirs = array_init();
|
||
srv->srvconf.reject_expect_100_with_417 = 1;
|
||
/* use syslog */
|
||
srv->errorlog_fd = STDERR_FILENO;
|
||
... | ... | |
CLEAN(srvconf.pid_file);
|
||
CLEAN(srvconf.modules_dir);
|
||
CLEAN(srvconf.network_backend);
|
||
CLEAN(srvconf.reject_expect_100_with_417);
|
||
CLEAN(tmp_chunk_len);
|
||
#undef CLEAN
|