summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-06-06 01:17:43 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2019-06-06 02:48:43 -0400
commite20b5318d51f32b259c9edc8a16d919b139e6d10 (patch)
tree7541e1a01074e4c3095f82780447844ffb233d77
parent02cd38687b6e805651483a9ac2827377b1d1977a (diff)
downloadlighttpd1.4-e20b5318d51f32b259c9edc8a16d919b139e6d10.tar.gz
lighttpd1.4-e20b5318d51f32b259c9edc8a16d919b139e6d10.zip
[core] use buffer_eq_icase_ssn func
specialized buffer_eq_icase_ssn func replace strncasecmp() in cases where string lengths are known to be at least as large as the len being compared case-insensitively
-rw-r--r--src/array.c8
-rw-r--r--src/http-header-glue.c12
-rw-r--r--src/mod_proxy.c6
-rw-r--r--src/mod_ssi.c3
-rw-r--r--src/response.c2
-rw-r--r--src/stat_cache.c2
6 files changed, 17 insertions, 16 deletions
diff --git a/src/array.c b/src/array.c
index a317951d..a73fc763 100644
--- a/src/array.c
+++ b/src/array.c
@@ -400,7 +400,7 @@ array_match_key_prefix_nc_klen (const array * const a, const char * const s, con
for (size_t i = 0; i < a->used; ++i) {
const buffer * const key = a->data[i]->key;
const size_t klen = buffer_string_length(key);
- if (klen <= slen && 0 == strncasecmp(s, key->ptr, klen))
+ if (klen <= slen && buffer_eq_icase_ssn(s, key->ptr, klen))
return a->data[i];
}
return NULL;
@@ -440,7 +440,7 @@ array_match_value_prefix_nc (const array * const a, const buffer * const b)
for (size_t i = 0; i < a->used; ++i) {
const buffer * const value = ((data_string *)a->data[i])->value;
const size_t vlen = buffer_string_length(value);
- if (vlen <= blen && 0 == strncasecmp(b->ptr, value->ptr, vlen))
+ if (vlen <= blen && buffer_eq_icase_ssn(b->ptr, value->ptr, vlen))
return value;
}
return NULL;
@@ -470,7 +470,7 @@ array_match_key_suffix_nc (const array * const a, const buffer * const b)
for (size_t i = 0; i < a->used; ++i) {
const buffer * const key = a->data[i]->key;
const size_t klen = buffer_string_length(key);
- if (klen <= blen && 0 == strncasecmp(end - klen, key->ptr, klen))
+ if (klen <= blen && buffer_eq_icase_ssn(end - klen, key->ptr, klen))
return a->data[i];
}
return NULL;
@@ -500,7 +500,7 @@ array_match_value_suffix_nc (const array * const a, const buffer * const b)
for (size_t i = 0; i < a->used; ++i) {
const buffer * const value = ((data_string *)a->data[i])->value;
const size_t vlen = buffer_string_length(value);
- if (vlen <= blen && 0 == strncasecmp(end - vlen, value->ptr, vlen))
+ if (vlen <= blen && buffer_eq_icase_ssn(end - vlen, value->ptr, vlen))
return value;
}
return NULL;
diff --git a/src/http-header-glue.c b/src/http-header-glue.c
index b7f03309..d54f00cf 100644
--- a/src/http-header-glue.c
+++ b/src/http-header-glue.c
@@ -19,7 +19,6 @@
#include <time.h>
-#include "sys-strings.h"
#include "sys-socket.h"
#include <unistd.h>
@@ -641,7 +640,7 @@ static void http_response_xsendfile (server *srv, connection *con, buffer *path,
if (dlen <= xlen
&& (!con->conf.force_lowercase_filenames
? 0 == memcmp(path->ptr, ds->value->ptr, dlen)
- : 0 == strncasecmp(path->ptr, ds->value->ptr, dlen))) {
+ : buffer_eq_icase_ssn(path->ptr, ds->value->ptr, dlen))) {
break;
}
}
@@ -715,7 +714,7 @@ static void http_response_xsendfile2(server *srv, connection *con, const buffer
if (dlen <= xlen
&& (!con->conf.force_lowercase_filenames
? 0 == memcmp(b->ptr, ds->value->ptr, dlen)
- : 0 == strncasecmp(b->ptr, ds->value->ptr, dlen))) {
+ : buffer_eq_icase_ssn(b->ptr, ds->value->ptr, dlen))) {
break;
}
}
@@ -985,8 +984,11 @@ static int http_response_process_headers(server *srv, connection *con, http_resp
con->http_status = 502; /* Bad Gateway */
break;
}
- } else if (id == HTTP_HEADER_OTHER && key_len > 9
- && 0==strncasecmp(key, CONST_STR_LEN("Variable-"))) {
+ }
+ else if (id == HTTP_HEADER_OTHER && key_len > 9
+ && (key[0] & 0xdf) == 'V'
+ && buffer_eq_icase_ssn(key,
+ CONST_STR_LEN("Variable-"))) {
http_header_env_append(con, key + 9, key_len - 9, value, strlen(value));
}
continue;
diff --git a/src/mod_proxy.c b/src/mod_proxy.c
index a6b05b83..3336fab1 100644
--- a/src/mod_proxy.c
+++ b/src/mod_proxy.c
@@ -309,7 +309,7 @@ static const buffer * http_header_remap_host_match (buffer *b, size_t off, http_
if (NULL == k) continue;
mlen = buffer_string_length(k);
}
- if (mlen == alen && 0 == strncasecmp(s, k->ptr, alen)) {
+ if (buffer_eq_icase_ss(s, alen, k->ptr, mlen)) {
if (buffer_is_equal_string(ds->value, CONST_STR_LEN("-"))) {
return remap_hdrs->http_host;
}
@@ -462,7 +462,7 @@ static void http_header_remap_setcookie (buffer *b, size_t off, http_header_rema
++e;
switch ((int)(e - s - 1)) {
case 4:
- if (0 == strncasecmp(s, "path", 4)) {
+ if (buffer_eq_icase_ssn(s, "path", 4)) {
if (*e == '"') ++e;
if (*e != '/') continue;
off = (size_t)(e - b->ptr);
@@ -472,7 +472,7 @@ static void http_header_remap_setcookie (buffer *b, size_t off, http_header_rema
}
break;
case 6:
- if (0 == strncasecmp(s, "domain", 6)) {
+ if (buffer_eq_icase_ssn(s, "domain", 6)) {
size_t alen = 0;
if (*e == '"') ++e;
if (*e == '.') ++e;
diff --git a/src/mod_ssi.c b/src/mod_ssi.c
index eefd2944..00ac727a 100644
--- a/src/mod_ssi.c
+++ b/src/mod_ssi.c
@@ -17,7 +17,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include "sys-strings.h"
#include <sys/wait.h>
#include <ctype.h>
@@ -574,7 +573,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
if (!con->conf.force_lowercase_filenames
? buffer_is_equal_right_len(con->physical.path, con->physical.rel_path, remain)
:(buffer_string_length(con->physical.path) >= remain
- && 0 == strncasecmp(con->physical.path->ptr+buffer_string_length(con->physical.path)-remain, con->physical.rel_path->ptr+i, remain))) {
+ && buffer_eq_icase_ssn(con->physical.path->ptr+buffer_string_length(con->physical.path)-remain, con->physical.rel_path->ptr+i, remain))) {
buffer_copy_string_len(p->stat_fn, con->physical.path->ptr, buffer_string_length(con->physical.path)-remain);
buffer_append_string_len(p->stat_fn, srv->tmp_buf->ptr+i, buffer_string_length(srv->tmp_buf)-i);
} else {
diff --git a/src/response.c b/src/response.c
index 4ef569a9..9682f3e9 100644
--- a/src/response.c
+++ b/src/response.c
@@ -227,7 +227,7 @@ static handler_t http_response_physical_path_check(server *srv, connection *con)
size_t len = strlen(pathinfo), reqlen;
if (con->conf.force_lowercase_filenames
&& len <= (reqlen = buffer_string_length(con->request.uri))
- && 0 == strncasecmp(con->request.uri->ptr + reqlen - len, pathinfo, len)) {
+ && buffer_eq_icase_ssn(con->request.uri->ptr + reqlen - len, pathinfo, len)) {
/* attempt to preserve case-insensitive PATH_INFO
* (works in common case where mod_alias, mod_magnet, and other modules
* have not modified the PATH_INFO portion of request URI, or did so
diff --git a/src/stat_cache.c b/src/stat_cache.c
index 4e7ebf37..1cd27657 100644
--- a/src/stat_cache.c
+++ b/src/stat_cache.c
@@ -639,7 +639,7 @@ const buffer * stat_cache_mimetype_by_ext(const connection *con, const char *nam
/* suffix match */
const data_string *ds = (data_string *)con->conf.mimetypes->data[i];
const size_t klen = buffer_string_length(ds->key);
- if (klen <= nlen && 0 == strncasecmp(end-klen, ds->key->ptr, klen))
+ if (klen <= nlen && buffer_eq_icase_ssn(end-klen, ds->key->ptr, klen))
return ds->value;
}
}