summaryrefslogtreecommitdiff
path: root/src/configfile-glue.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-06-20 00:15:05 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2021-08-27 02:16:54 -0400
commit1de03a03ee03e3d715b51319752a52b23114e6f6 (patch)
tree1482170ee7717619a89eae22d14849c78d801564 /src/configfile-glue.c
parent4b9da9f1e8fb12dc136d1a384d003ac502385159 (diff)
downloadlighttpd-git-1de03a03ee03e3d715b51319752a52b23114e6f6.tar.gz
[core] reduce $HTTP["host"] compare str scanning
Diffstat (limited to 'src/configfile-glue.c')
-rw-r--r--src/configfile-glue.c53
1 files changed, 22 insertions, 31 deletions
diff --git a/src/configfile-glue.c b/src/configfile-glue.c
index 83d0d8a4..e0588c92 100644
--- a/src/configfile-glue.c
+++ b/src/configfile-glue.c
@@ -462,42 +462,33 @@ static cond_result_t config_check_cond_nocache(request_st * const r, const data_
const buffer *l;
switch (dc->comp) {
case COMP_HTTP_HOST:
-
l = &r->uri.authority;
-
- if (buffer_is_blank(l)) {
+ if (__builtin_expect( (buffer_is_blank(l)), 0)) {
l = (buffer *)&empty_string;
break;
}
-
- switch(dc->cond) {
- case CONFIG_COND_NE:
- case CONFIG_COND_EQ: {
- unsigned short port = sock_addr_get_port(&r->con->srv_socket->addr);
- if (0 == port) break;
- const char *ck_colon = strchr(dc->string.ptr, ':');
- const char *val_colon = strchr(l->ptr, ':');
-
- /* append server-port if necessary */
- if (NULL != ck_colon && NULL == val_colon) {
- /* condition "host:port" but client send "host" */
- buffer *tb = r->tmp_buf;
- buffer_copy_buffer(tb, l);
- buffer_append_string_len(tb, CONST_STR_LEN(":"));
- buffer_append_int(tb, port);
- l = tb;
- } else if (NULL != val_colon && NULL == ck_colon) {
- /* condition "host" but client send "host:port" */
- buffer *tb = r->tmp_buf;
- buffer_copy_string_len(tb, l->ptr, val_colon - l->ptr);
- l = tb;
- }
- break;
- }
- default:
- break;
+ if ((dc->cond == CONFIG_COND_EQ || dc->cond == CONFIG_COND_NE)
+ && dc->string.ptr[0] != '/') { /*(AF_UNIX addr is string)*/
+ uint_fast32_t llen = buffer_clen(l);
+ uint_fast32_t dlen = buffer_clen(&dc->string);
+ if (llen == dlen)
+ break;
+ /* check names match, whether or not :port suffix present */
+ /*(not strictly checking for port match for alt-svc flexibility,
+ * though if strings are same length, port is checked for match)*/
+ /*(r->uri.authority not strictly checked here for excess ':')*/
+ /*(r->uri.authority lowercased during request parsing)*/
+ if (debug_cond)
+ log_error(r->conf.errh, __FILE__, __LINE__,
+ "%s compare to %s", dc->comp_key, l->ptr);
+ int match = ((llen > dlen)
+ ? l->ptr[dlen] == ':' && llen - dlen <= 5
+ : dc->string.ptr[(dlen = llen)] == ':')
+ && 0 == memcmp(l->ptr, dc->string.ptr, dlen);
+ return match ^ (dc->cond == CONFIG_COND_EQ)
+ ? COND_RESULT_FALSE
+ : COND_RESULT_TRUE;
}
-
break;
case COMP_HTTP_REMOTE_IP: {
/* handle remoteip limitations