[core] remove buffer_is_equal_right_len()

(not widely used or widely useful)
This commit is contained in:
Glenn Strauss 2021-05-06 22:51:39 -04:00
parent e0a4a7849f
commit 1aae63af62
5 changed files with 11 additions and 26 deletions

View File

@ -426,19 +426,6 @@ int buffer_is_equal_string(const buffer *a, const char *s, size_t b_len) {
return (a->used == b_len + 1 && 0 == memcmp(a->ptr, s, b_len));
}
int buffer_is_equal_right_len(const buffer *b1, const buffer *b2, size_t len) {
/* no len -> equal */
if (len == 0) return 1;
/* len > 0, but empty buffers -> not equal */
if (b1->used == 0 || b2->used == 0) return 0;
/* buffers too small -> not equal */
if (b1->used - 1 < len || b2->used - 1 < len) return 0;
return 0 == memcmp(b1->ptr + b1->used - 1 - len, b2->ptr + b2->used - 1 - len, len);
}
void li_tohex_lc(char * const restrict buf, size_t buf_len, const char * const restrict s, size_t s_len) {
force_assert(2 * s_len > s_len);

View File

@ -186,10 +186,6 @@ __attribute_nonnull__
__attribute_pure__
int buffer_is_equal(const buffer *a, const buffer *b);
__attribute_nonnull__
__attribute_pure__
int buffer_is_equal_right_len(const buffer *a, const buffer *b, size_t len);
__attribute_nonnull__
__attribute_pure__
int buffer_is_equal_string(const buffer *a, const char *s, size_t b_len);

View File

@ -258,9 +258,11 @@ URIHANDLER_FUNC(mod_cml_is_handled) {
mod_cml_patch_config(r, p);
if (buffer_string_is_empty(p->conf.ext)) return HANDLER_GO_ON;
const uint32_t elen = buffer_string_length(p->conf.ext);
if (0 == elen) return HANDLER_GO_ON;
if (!buffer_is_equal_right_len(&r->physical.path, p->conf.ext, buffer_string_length(p->conf.ext))) {
const uint32_t plen = buffer_string_length(&r->physical.path);
if (plen < elen || 0 != memcmp(r->physical.path.ptr+plen-elen, p->conf.ext->ptr, elen)) {
return HANDLER_GO_ON;
}

View File

@ -556,14 +556,14 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
buffer_to_lower(tb);
}
uint32_t remain = buffer_string_length(&r->uri.path) - i;
if (!r->conf.force_lowercase_filenames
? buffer_is_equal_right_len(&r->physical.path, &r->physical.rel_path, remain)
:(buffer_string_length(&r->physical.path) >= remain
&& buffer_eq_icase_ssn(r->physical.path.ptr+buffer_string_length(&r->physical.path)-remain, r->physical.rel_path.ptr+i, remain))) {
uint32_t plen = buffer_string_length(&r->physical.path);
if (plen >= remain
&& (!r->conf.force_lowercase_filenames
? 0 == memcmp(r->physical.path.ptr+plen-remain, r->physical.rel_path.ptr+i, remain)
: buffer_eq_icase_ssn(r->physical.path.ptr+plen-remain, r->physical.rel_path.ptr+i, remain))) {
buffer_copy_path_len2(p->stat_fn,
r->physical.path.ptr,
buffer_string_length(&r->physical.path)
- remain,
plen-remain,
tb->ptr+i,
buffer_string_length(tb)-i);
} else {

View File

@ -430,7 +430,7 @@ static int wstunnel_is_allowed_origin(request_st * const r, handler_ctx * const
buffer *b = &((data_string *)allowed_origins->data[i])->value;
size_t blen = buffer_string_length(b);
if ((olen > blen ? origin->ptr[olen-blen-1] == '.' : olen == blen)
&& buffer_is_equal_right_len(origin, b, blen)) {
&& 0 == memcmp(origin->ptr+olen-blen, b->ptr, blen)) {
DEBUG_LOG_INFO("%s matches allowed origin: %s",origin->ptr,b->ptr);
return 1;
}