Browse Source

[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
personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
e20b5318d5
  1. 8
      src/array.c
  2. 12
      src/http-header-glue.c
  3. 6
      src/mod_proxy.c
  4. 3
      src/mod_ssi.c
  5. 2
      src/response.c
  6. 2
      src/stat_cache.c

8
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;

12
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;

6
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;

3
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 {

2
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

2
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;
}
}

Loading…
Cancel
Save