Browse Source

[multiple] buffer_copy_path_len2() aggregate

master
Glenn Strauss 8 months ago
parent
commit
680e6b3bca
  1. 10
      src/buffer.c
  2. 1
      src/buffer.h
  3. 6
      src/chunk.c
  4. 9
      src/configfile.c
  5. 7
      src/gw_backend.c
  6. 18
      src/http_cgi.c
  7. 17
      src/mod_cml_lua.c
  8. 4
      src/mod_deflate.c
  9. 4
      src/mod_gnutls.c
  10. 4
      src/mod_mbedtls.c
  11. 4
      src/mod_nss.c
  12. 4
      src/mod_openssl.c
  13. 6
      src/mod_secdownload.c
  14. 24
      src/mod_ssi.c
  15. 8
      src/mod_userdir.c
  16. 14
      src/mod_webdav.c
  17. 4
      src/mod_wolfssl.c
  18. 4
      src/plugin.c
  19. 5
      src/response.c

10
src/buffer.c

@ -258,6 +258,16 @@ void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t
memcpy(s, a, alen);
}
void
buffer_copy_path_len2 (buffer * const restrict b, const char * const restrict s1, size_t len1, const char * const restrict s2, size_t len2)
{
/*(similar to buffer_copy_string_len(b, s1, len1) but combined allocation)*/
memcpy(buffer_string_prepare_copy(b, len1+len2+1), s1, len1);
b->used = len1 + 1; /*('\0' byte will be written below)*/
buffer_append_path_len(b, s2, len2);/*(choice: not inlined, special-cased)*/
}
void buffer_append_uint_hex_lc(buffer *b, uintmax_t value) {
char *buf;
unsigned int shift = 0;

1
src/buffer.h

@ -279,6 +279,7 @@ __attribute_nonnull__
static inline void buffer_append_slash(buffer *b); /* append '/' no non-empty strings not ending in '/' */
void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t alen); /* join strings with '/', if '/' not present */
void buffer_copy_path_len2(buffer * restrict b, const char * restrict s1, size_t len1, const char * restrict s2, size_t len2);
__attribute_nonnull__
__attribute_pure__

6
src/chunk.c

@ -615,9 +615,9 @@ static chunk *chunkqueue_get_append_tempfile(chunkqueue * const restrict cq, log
for (errno = EIO; cq->tempdir_idx < cq->tempdirs->used; ++cq->tempdir_idx) {
data_string *ds = (data_string *)cq->tempdirs->data[cq->tempdir_idx];
buffer_copy_buffer(template, &ds->value);
buffer_append_path_len(template, CONST_STR_LEN("lighttpd-upload-XXXXXX"));
buffer_copy_path_len2(template,
CONST_BUF_LEN(&ds->value),
CONST_STR_LEN("lighttpd-upload-XXXXXX"));
if (-1 != (fd = fdevent_mkstemp_append(template->ptr))) break;
}
} else {

9
src/configfile.c

@ -2014,7 +2014,8 @@ static int config_parse_file_stream(server *srv, config_t *context, const char *
}
int config_parse_file(server *srv, config_t *context, const char *fn) {
buffer *filename;
buffer * const filename = buffer_init();
const size_t fnlen = strlen(fn);
int ret = -1;
#ifdef GLOB_BRACE
int flags = GLOB_BRACE;
@ -2026,10 +2027,10 @@ int config_parse_file(server *srv, config_t *context, const char *fn) {
if ((fn[0] == '/' || fn[0] == '\\') ||
(fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\')) ||
(fn[0] == '.' && fn[1] == '.' && (fn[2] == '/' || fn[2] == '\\'))) {
filename = buffer_init_string(fn);
buffer_copy_string_len(filename, fn, fnlen);
} else {
filename = buffer_init_buffer(context->basedir);
buffer_append_path_len(filename, fn, strlen(fn));
buffer_copy_path_len2(filename, CONST_BUF_LEN(context->basedir),
fn, fnlen);
}
switch (glob(filename->ptr, flags, NULL, &gl)) {

7
src/gw_backend.c

@ -2195,10 +2195,9 @@ static handler_t gw_recv_response(gw_handler_ctx * const hctx, request_st * cons
if (!buffer_string_is_empty(host->docroot)) {
buffer_copy_buffer(&r->physical.doc_root, host->docroot);
buffer_copy_buffer(&r->physical.basedir, host->docroot);
buffer_copy_buffer(&r->physical.path, host->docroot);
buffer_append_path_len(&r->physical.path,
CONST_BUF_LEN(&r->uri.path));
buffer_copy_path_len2(&r->physical.path,
CONST_BUF_LEN(host->docroot),
CONST_BUF_LEN(&r->uri.path));
physpath = r->physical.path.ptr;
}

18
src/http_cgi.c

@ -194,11 +194,11 @@ http_cgi_headers (request_st * const r, http_cgi_opts * const opts, http_cgi_hea
/* PATH_TRANSLATED is only defined if PATH_INFO is set
* Note: not implemented: re-url-encode '?' '=' ';' for
* (RFC 3875 4.1.6) */
if (!buffer_string_is_empty(opts->docroot))
buffer_copy_buffer(tb, opts->docroot);
else
buffer_copy_buffer(tb, &r->physical.basedir);
buffer_append_path_len(tb, CONST_BUF_LEN(&r->pathinfo));
const buffer * const bd = (!buffer_string_is_empty(opts->docroot))
? opts->docroot
: &r->physical.basedir;
buffer_copy_path_len2(tb, CONST_BUF_LEN(bd),
CONST_BUF_LEN(&r->pathinfo));
rc |= cb(vdata, CONST_STR_LEN("PATH_TRANSLATED"),
CONST_BUF_LEN(tb));
}
@ -213,8 +213,8 @@ http_cgi_headers (request_st * const r, http_cgi_opts * const opts, http_cgi_hea
if (!buffer_string_is_empty(opts->docroot)) {
/* alternate docroot, e.g. for remote FastCGI or SCGI server */
buffer_copy_buffer(tb, opts->docroot);
buffer_append_path_len(tb, CONST_BUF_LEN(&r->uri.path));
buffer_copy_path_len2(tb, CONST_BUF_LEN(opts->docroot),
CONST_BUF_LEN(&r->uri.path));
rc |= cb(vdata, CONST_STR_LEN("SCRIPT_FILENAME"),
CONST_BUF_LEN(tb));
rc |= cb(vdata, CONST_STR_LEN("DOCUMENT_ROOT"),
@ -227,8 +227,8 @@ http_cgi_headers (request_st * const r, http_cgi_opts * const opts, http_cgi_hea
*
* see src/sapi/cgi_main.c, init_request_info()
*/
buffer_copy_buffer(tb, &r->physical.path);
buffer_append_path_len(tb, CONST_BUF_LEN(&r->pathinfo));
buffer_copy_path_len2(tb, CONST_BUF_LEN(&r->physical.path),
CONST_BUF_LEN(&r->pathinfo));
rc |= cb(vdata, CONST_STR_LEN("SCRIPT_FILENAME"),
CONST_BUF_LEN(tb));
}

17
src/mod_cml_lua.c

@ -227,8 +227,8 @@ int cache_parse_lua(request_st * const r, plugin_data * const p, const buffer *
/* the file is relative, make it absolute */
if (s[0] != '/') {
buffer_copy_buffer(b, &p->basedir);
buffer_append_path_len(b, s, (uint32_t)slen);
buffer_copy_path_len2(b, CONST_BUF_LEN(&p->basedir),
s, slen);
} else {
buffer_copy_string_len(b, s, (uint32_t)slen);
}
@ -299,11 +299,14 @@ int cache_parse_lua(request_st * const r, plugin_data * const p, const buffer *
if (ret == 1 && !buffer_string_is_empty(&p->trigger_handler)) {
/* cache-miss */
buffer_copy_buffer(&r->uri.path, &p->baseurl);
buffer_append_string_buffer(&r->uri.path, &p->trigger_handler);
buffer_copy_buffer(&r->physical.path, &p->basedir);
buffer_append_path_len(&r->physical.path, CONST_BUF_LEN(&p->trigger_handler));
buffer_clear(&r->uri.path);
buffer_append_str2(&r->uri.path,
CONST_BUF_LEN(&p->baseurl),
CONST_BUF_LEN(&p->trigger_handler));
buffer_copy_path_len2(&r->physical.path,
CONST_BUF_LEN(&p->basedir),
CONST_BUF_LEN(&p->trigger_handler));
chunkqueue_reset(&r->write_queue);
}

4
src/mod_deflate.c

@ -294,8 +294,8 @@ static buffer * mod_deflate_cache_file_name(request_st * const r, const buffer *
* (matching) &r->pathinfo suffix, with result url-encoded
* Alternative, we could shard etag which is already our "checksum" */
buffer * const tb = r->tmp_buf;
buffer_copy_buffer(tb, cache_dir);
buffer_append_path_len(tb, CONST_BUF_LEN(&r->physical.path));
buffer_copy_path_len2(tb, CONST_BUF_LEN(cache_dir),
CONST_BUF_LEN(&r->physical.path));
buffer_append_str2(tb, CONST_STR_LEN("-"), /*(strip surrounding '"')*/
etag->ptr+1, buffer_string_length(etag)-2);
return tb;

4
src/mod_gnutls.c

@ -1243,8 +1243,8 @@ mod_gnutls_acme_tls_1 (handler_ctx *hctx)
if (0 != http_request_host_policy(name, hctx->r->conf.http_parseopts, 443))
return rc;
#endif
buffer_copy_buffer(b, hctx->conf.ssl_acme_tls_1);
buffer_append_path_len(b, CONST_BUF_LEN(name));
buffer_copy_path_len2(b, CONST_BUF_LEN(hctx->conf.ssl_acme_tls_1),
CONST_BUF_LEN(name));
#if 0

4
src/mod_mbedtls.c

@ -1004,8 +1004,8 @@ mod_mbedtls_acme_tls_1 (handler_ctx *hctx)
if (0 != http_request_host_policy(name,hctx->r->conf.http_parseopts,443))
return rc;
#endif
buffer_copy_buffer(b, hctx->conf.ssl_acme_tls_1);
buffer_append_path_len(b, CONST_BUF_LEN(name));
buffer_copy_path_len2(b, CONST_BUF_LEN(hctx->conf.ssl_acme_tls_1),
CONST_BUF_LEN(name));
len = buffer_string_length(b);
do {

4
src/mod_nss.c

@ -1210,8 +1210,8 @@ mod_nss_acme_tls_1 (handler_ctx *hctx)
if (0 != http_request_host_policy(name, hctx->r->conf.http_parseopts, 443))
return SECFailure;
#endif
buffer_copy_buffer(b, hctx->conf.ssl_acme_tls_1);
buffer_append_path_len(b, CONST_BUF_LEN(name));
buffer_copy_path_len2(b, CONST_BUF_LEN(hctx->conf.ssl_acme_tls_1),
CONST_BUF_LEN(name));
/* cert and key load is similar to network_nss_load_pemfile() */

4
src/mod_openssl.c

@ -1730,8 +1730,8 @@ mod_openssl_acme_tls_1 (SSL *ssl, handler_ctx *hctx)
if (0 != http_request_host_policy(name,hctx->r->conf.http_parseopts,443))
return rc;
#endif
buffer_copy_buffer(b, hctx->conf.ssl_acme_tls_1);
buffer_append_path_len(b, CONST_BUF_LEN(name));
buffer_copy_path_len2(b, CONST_BUF_LEN(hctx->conf.ssl_acme_tls_1),
CONST_BUF_LEN(name));
len = buffer_string_length(b);
do {

6
src/mod_secdownload.c

@ -503,9 +503,9 @@ URIHANDLER_FUNC(mod_secdownload_uri_handler) {
buffer_copy_buffer(&r->physical.doc_root, p->conf.doc_root);
buffer_copy_buffer(&r->physical.basedir, p->conf.doc_root);
buffer_copy_string(&r->physical.rel_path, rel_uri);
buffer_copy_buffer(&r->physical.path, &r->physical.doc_root);
buffer_append_path_len(&r->physical.path,
CONST_BUF_LEN(&r->physical.rel_path));
buffer_copy_path_len2(&r->physical.path,
CONST_BUF_LEN(&r->physical.doc_root),
CONST_BUF_LEN(&r->physical.rel_path));
return HANDLER_GO_ON;
}

24
src/mod_ssi.c

@ -493,10 +493,6 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
if (file_path) {
/* current doc-root */
char *sl = strrchr(r->physical.path.ptr, '/');
if (NULL == sl) break; /*(not expected)*/
buffer_copy_string_len(p->stat_fn, r->physical.path.ptr, sl - r->physical.path.ptr + 1);
buffer_copy_string(tb, file_path);
buffer_urldecode_path(tb);
if (!buffer_is_valid_UTF8(tb)) {
@ -505,7 +501,12 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
break;
}
buffer_path_simplify(tb, tb);
buffer_append_path_len(p->stat_fn, CONST_BUF_LEN(tb));
char *sl = strrchr(r->physical.path.ptr, '/');
if (NULL == sl) break; /*(not expected)*/
buffer_copy_path_len2(p->stat_fn,
r->physical.path.ptr,
sl - r->physical.path.ptr + 1,
CONST_BUF_LEN(tb));
} else {
/* virtual */
@ -559,13 +560,18 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
? 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))) {
buffer_copy_string_len(p->stat_fn, r->physical.path.ptr, buffer_string_length(&r->physical.path)-remain);
buffer_append_path_len(p->stat_fn, tb->ptr+i, buffer_string_length(tb)-i);
buffer_copy_path_len2(p->stat_fn,
r->physical.path.ptr,
buffer_string_length(&r->physical.path)
- remain,
tb->ptr+i,
buffer_string_length(tb)-i);
} else {
/* unable to perform physical path remap here;
* assume doc_root/rel_path and no remapping */
buffer_copy_buffer(p->stat_fn, &r->physical.doc_root);
buffer_append_path_len(p->stat_fn, CONST_BUF_LEN(tb));
buffer_copy_path_len2(p->stat_fn,
CONST_BUF_LEN(&r->physical.doc_root),
CONST_BUF_LEN(tb));
}
}

8
src/mod_userdir.c

@ -173,13 +173,13 @@ static handler_t mod_userdir_docroot_construct(request_st * const r, plugin_data
}
struct passwd *pwd;
if (cached >= 0) {
buffer_copy_buffer(b, &p->cache_path[cached]);
buffer_append_path_len(b, CONST_BUF_LEN(p->conf.path));
buffer_copy_path_len2(b, CONST_BUF_LEN(&p->cache_path[cached]),
CONST_BUF_LEN(p->conf.path));
}
else if ((pwd = getpwnam(u))) {
const size_t plen = strlen(pwd->pw_dir);
buffer_copy_string_len(b, pwd->pw_dir, plen);
buffer_append_path_len(b, CONST_BUF_LEN(p->conf.path));
buffer_copy_path_len2(b, pwd->pw_dir, plen,
CONST_BUF_LEN(p->conf.path));
if (!stat_cache_path_isdir(b)) {
return HANDLER_GO_ON;
}

14
src/mod_webdav.c

@ -4829,11 +4829,11 @@ mod_webdav_copymove_b (request_st * const r, const plugin_config * const pconf,
#ifdef __COVERITY__
force_assert(2 <= dst_rel_path->used);
#endif
buffer_copy_string_len(dst_path, r->physical.path.ptr,
r->physical.path.used - 1 - remain);
buffer_append_path_len(dst_path,
dst_rel_path->ptr+i,
dst_rel_path->used - 1 - i);
buffer_copy_path_len2(dst_path,
r->physical.path.ptr,
r->physical.path.used - 1 - remain,
dst_rel_path->ptr+i,
dst_rel_path->used - 1 - i);
if (buffer_string_length(dst_path) >= PATH_MAX) {
http_status_set_error(r, 403); /* Forbidden */
return HANDLER_FINISHED;
@ -4842,8 +4842,8 @@ mod_webdav_copymove_b (request_st * const r, const plugin_config * const pconf,
else { /*(not expected; some other module mucked with path or rel_path)*/
/* unable to perform physical path remap here;
* assume doc_root/rel_path and no remapping */
buffer_copy_buffer(dst_path, &r->physical.doc_root);
buffer_append_path_len(dst_path, CONST_BUF_LEN(dst_rel_path));
buffer_copy_path_len2(dst_path, CONST_BUF_LEN(&r->physical.doc_root),
CONST_BUF_LEN(dst_rel_path));
if (buffer_string_length(dst_path) >= PATH_MAX) {
http_status_set_error(r, 403); /* Forbidden */
return HANDLER_FINISHED;

4
src/mod_wolfssl.c

@ -1661,8 +1661,8 @@ mod_openssl_acme_tls_1 (SSL *ssl, handler_ctx *hctx)
if (0 != http_request_host_policy(name,hctx->r->conf.http_parseopts,443))
return rc;
#endif
buffer_copy_buffer(b, hctx->conf.ssl_acme_tls_1);
buffer_append_path_len(b, CONST_BUF_LEN(name));
buffer_copy_path_len2(b, CONST_BUF_LEN(hctx->conf.ssl_acme_tls_1),
CONST_BUF_LEN(name));
len = buffer_string_length(b);
do {

4
src/plugin.c

@ -158,8 +158,8 @@ int plugins_load(server *srv) {
for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) {
const buffer * const module = &((data_string *)srv->srvconf.modules->data[i])->value;
buffer_copy_buffer(tb, srv->srvconf.modules_dir);
buffer_append_path_len(tb, CONST_BUF_LEN(module));
buffer_copy_path_len2(tb, CONST_BUF_LEN(srv->srvconf.modules_dir),
CONST_BUF_LEN(module));
#if defined(__WIN32) || defined(__CYGWIN__)
buffer_append_string_len(tb, CONST_STR_LEN(".dll"));
#else

5
src/response.c

@ -524,8 +524,9 @@ http_response_prepare (request_st * const r)
*/
buffer_copy_buffer(&r->physical.basedir, &r->physical.doc_root);
buffer_copy_buffer(&r->physical.path, &r->physical.doc_root);
buffer_append_path_len(&r->physical.path, CONST_BUF_LEN(&r->physical.rel_path));
buffer_copy_path_len2(&r->physical.path,
CONST_BUF_LEN(&r->physical.doc_root),
CONST_BUF_LEN(&r->physical.rel_path));
if (r->conf.log_request_handling) {
log_error(r->conf.errh, __FILE__, __LINE__,

Loading…
Cancel
Save