From ef4d14fc2177dc7c6a941afd6a81009342a6a1d1 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 2 Jun 2015 13:40:41 +0000 Subject: [PATCH] Merge r1681795, r1682988, r1682979, r1682819, r1682816 from trunk: initialize args to not print garbage mem during a RewriteRule parse error Initialize args to not print garbage mem during a RewriteCond parse error (same as r1681795 for RewriteRule) Improve style in examples. Improve error message (related to PR57311 diagnostic) Concat string at compile time in order to save a few cycles. Submitted by: covener, jailletc36, jailletc36, jailletc36, jailletc36 Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1683113 13f79535-47bb-0310-9956-ffa450edef68 --- STATUS | 15 ------ modules/examples/mod_case_filter.c | 76 +++++++++++++-------------- modules/examples/mod_case_filter_in.c | 16 +++--- modules/examples/mod_example_hooks.c | 9 ++-- modules/examples/mod_example_ipc.c | 21 +++++--- modules/mappers/mod_rewrite.c | 8 +-- modules/proxy/mod_proxy_wstunnel.c | 2 +- modules/proxy/proxy_util.c | 2 +- 8 files changed, 67 insertions(+), 82 deletions(-) diff --git a/STATUS b/STATUS index 6bab9da7f1..977f03ba04 100644 --- a/STATUS +++ b/STATUS @@ -105,21 +105,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) Easy patches - synch with trunk - - mod_rewrite: Initialize args to not print garbage mem during a RewriteCond parse error - - mod_rewrite: Initialize args to not print garbage mem during a RewriteRule parse error - - examples/mod_*: Improve style in examples. - - proxy_util: Improve error message - - mod_proxy_wstunnel: Concat string at compile time in orser to save a few cycles. - trunk patch: - http://svn.apache.org/r1681795 - http://svn.apache.org/r1682988 - http://svn.apache.org/r1682979 - http://svn.apache.org/r1682819 - http://svn.apache.org/r1682816 - 2.4.x patch: trunk patchs work - +1: jailletc36, ylavic, jim - PATCHES PROPOSED TO BACKPORT FROM TRUNK: diff --git a/modules/examples/mod_case_filter.c b/modules/examples/mod_case_filter.c index f0b84d2900..409f65bfa6 100644 --- a/modules/examples/mod_case_filter.c +++ b/modules/examples/mod_case_filter.c @@ -24,43 +24,43 @@ #include -static const char s_szCaseFilterName[]="CaseFilter"; +static const char s_szCaseFilterName[] = "CaseFilter"; module AP_MODULE_DECLARE_DATA case_filter_module; typedef struct - { +{ int bEnabled; - } CaseFilterConfig; +} CaseFilterConfig; -static void *CaseFilterCreateServerConfig(apr_pool_t *p,server_rec *s) - { - CaseFilterConfig *pConfig=apr_pcalloc(p,sizeof *pConfig); +static void *CaseFilterCreateServerConfig(apr_pool_t *p, server_rec *s) +{ + CaseFilterConfig *pConfig = apr_pcalloc(p,sizeof *pConfig); - pConfig->bEnabled=0; + pConfig->bEnabled = 0; return pConfig; - } +} static void CaseFilterInsertFilter(request_rec *r) - { - CaseFilterConfig *pConfig=ap_get_module_config(r->server->module_config, - &case_filter_module); +{ + CaseFilterConfig *pConfig = ap_get_module_config(r->server->module_config, + &case_filter_module); - if(!pConfig->bEnabled) + if (!pConfig->bEnabled) return; - ap_add_output_filter(s_szCaseFilterName,NULL,r,r->connection); - } + ap_add_output_filter(s_szCaseFilterName, NULL, r, r->connection); +} static apr_status_t CaseFilterOutFilter(ap_filter_t *f, apr_bucket_brigade *pbbIn) - { +{ request_rec *r = f->r; conn_rec *c = r->connection; apr_bucket *pbktIn; apr_bucket_brigade *pbbOut; - pbbOut=apr_brigade_create(r->pool, c->bucket_alloc); + pbbOut = apr_brigade_create(r->pool, c->bucket_alloc); for (pbktIn = APR_BRIGADE_FIRST(pbbIn); pbktIn != APR_BRIGADE_SENTINEL(pbbIn); pbktIn = APR_BUCKET_NEXT(pbktIn)) @@ -71,25 +71,25 @@ static apr_status_t CaseFilterOutFilter(ap_filter_t *f, apr_size_t n; apr_bucket *pbktOut; - if(APR_BUCKET_IS_EOS(pbktIn)) - { - apr_bucket *pbktEOS=apr_bucket_eos_create(c->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS); + if (APR_BUCKET_IS_EOS(pbktIn)) { + apr_bucket *pbktEOS = apr_bucket_eos_create(c->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(pbbOut, pbktEOS); continue; - } + } /* read */ - apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ); + apr_bucket_read(pbktIn, &data, &len, APR_BLOCK_READ); /* write */ buf = apr_bucket_alloc(len, c->bucket_alloc); - for(n=0 ; n < len ; ++n) + for (n=0 ; n < len ; ++n) { buf[n] = apr_toupper(data[n]); + } pbktOut = apr_bucket_heap_create(buf, len, apr_bucket_free, c->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut); - } + APR_BRIGADE_INSERT_TAIL(pbbOut, pbktOut); + } /* Q: is there any advantage to passing a brigade for each bucket? * A: obviously, it can cut down server resource consumption, if this @@ -101,31 +101,31 @@ static apr_status_t CaseFilterOutFilter(ap_filter_t *f, * don't let our caller pass the same buckets to us, twice; */ apr_brigade_cleanup(pbbIn); - return ap_pass_brigade(f->next,pbbOut); - } + return ap_pass_brigade(f->next, pbbOut); +} static const char *CaseFilterEnable(cmd_parms *cmd, void *dummy, int arg) - { - CaseFilterConfig *pConfig=ap_get_module_config(cmd->server->module_config, - &case_filter_module); - pConfig->bEnabled=arg; +{ + CaseFilterConfig *pConfig = ap_get_module_config(cmd->server->module_config, + &case_filter_module); + pConfig->bEnabled = arg; return NULL; - } +} static const command_rec CaseFilterCmds[] = - { +{ AP_INIT_FLAG("CaseFilter", CaseFilterEnable, NULL, RSRC_CONF, "Run a case filter on this host"), { NULL } - }; +}; static void CaseFilterRegisterHooks(apr_pool_t *p) - { - ap_hook_insert_filter(CaseFilterInsertFilter,NULL,NULL,APR_HOOK_MIDDLE); - ap_register_output_filter(s_szCaseFilterName,CaseFilterOutFilter,NULL, +{ + ap_hook_insert_filter(CaseFilterInsertFilter, NULL, NULL, APR_HOOK_MIDDLE); + ap_register_output_filter(s_szCaseFilterName, CaseFilterOutFilter, NULL, AP_FTYPE_RESOURCE); - } +} AP_DECLARE_MODULE(case_filter) = { diff --git a/modules/examples/mod_case_filter_in.c b/modules/examples/mod_case_filter_in.c index 73af077afa..7200765b3a 100644 --- a/modules/examples/mod_case_filter_in.c +++ b/modules/examples/mod_case_filter_in.c @@ -53,12 +53,12 @@ static void *CaseFilterInCreateServerConfig(apr_pool_t *p, server_rec *s) static void CaseFilterInInsertFilter(request_rec *r) { - CaseFilterInConfig *pConfig=ap_get_module_config(r->server->module_config, - &case_filter_in_module); - if(!pConfig->bEnabled) + CaseFilterInConfig *pConfig = ap_get_module_config(r->server->module_config, + &case_filter_in_module); + if (!pConfig->bEnabled) return; - ap_add_input_filter(s_szCaseFilterName,NULL,r,r->connection); + ap_add_input_filter(s_szCaseFilterName, NULL, r, r->connection); } static apr_status_t CaseFilterInFilter(ap_filter_t *f, @@ -84,7 +84,7 @@ static apr_status_t CaseFilterInFilter(ap_filter_t *f, return ret; } - while(!APR_BRIGADE_EMPTY(pCtx->pbbTmp)) { + while (!APR_BRIGADE_EMPTY(pCtx->pbbTmp)) { apr_bucket *pbktIn = APR_BRIGADE_FIRST(pCtx->pbbTmp); apr_bucket *pbktOut; const char *data; @@ -106,12 +106,13 @@ static apr_status_t CaseFilterInFilter(ap_filter_t *f, } ret=apr_bucket_read(pbktIn, &data, &len, eBlock); - if(ret != APR_SUCCESS) + if (ret != APR_SUCCESS) return ret; buf = ap_malloc(len); - for(n=0 ; n < len ; ++n) + for (n=0 ; n < len ; ++n) { buf[n] = apr_toupper(data[n]); + } pbktOut = apr_bucket_heap_create(buf, len, 0, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut, pbktOut); @@ -121,7 +122,6 @@ static apr_status_t CaseFilterInFilter(ap_filter_t *f, return APR_SUCCESS; } - static const char *CaseFilterInEnable(cmd_parms *cmd, void *dummy, int arg) { CaseFilterInConfig *pConfig diff --git a/modules/examples/mod_example_hooks.c b/modules/examples/mod_example_hooks.c index 1130f7eb39..4db0865ccc 100644 --- a/modules/examples/mod_example_hooks.c +++ b/modules/examples/mod_example_hooks.c @@ -329,7 +329,8 @@ static void example_log_each(apr_pool_t *p, server_rec *s, const char *note) { if (s != NULL) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_example_hooks: %s", note); - } else { + } + else { apr_file_t *out = NULL; apr_file_open_stderr(&out, p); apr_file_printf(out, "mod_example_hooks traced in non-loggable " @@ -741,7 +742,6 @@ static int x_pre_config(apr_pool_t *pconf, apr_pool_t *plog, * Log the call and exit. */ trace_startup(ptemp, NULL, NULL, "x_pre_config()"); - return OK; } @@ -1049,7 +1049,8 @@ static int x_handler(request_rec *r) r->connection->pool); if ((status == APR_SUCCESS) && conn_data) { ap_rprintf(r, "
    \n%s
\n", (char *) conn_data); - } else { + } + else { ap_rputs("

No connection-specific callback information was " "retrieved.

\n", r); } @@ -1135,7 +1136,6 @@ static int x_pre_connection(conn_rec *c, void *csd) static int x_process_connection(conn_rec *c) { trace_connection(c, "x_process_connection()"); - return DECLINED; } @@ -1181,7 +1181,6 @@ static int x_post_read_request(request_rec *r) */ static int x_translate_name(request_rec *r) { - /* * We don't actually *do* anything here, except note the fact that we were * called. diff --git a/modules/examples/mod_example_ipc.c b/modules/examples/mod_example_ipc.c index b8ba569c06..a7cdb34d1b 100644 --- a/modules/examples/mod_example_ipc.c +++ b/modules/examples/mod_example_ipc.c @@ -91,7 +91,8 @@ typedef struct exipc_data { * on restarts. It assures that the new children will not talk to a stale * shared memory segment. */ -static apr_status_t shm_cleanup_wrapper(void *unused) { +static apr_status_t shm_cleanup_wrapper(void *unused) +{ if (exipc_shm) return apr_shm_destroy(exipc_shm); return OK; @@ -248,10 +249,12 @@ static int exipc_handler(request_rec *r) rs = apr_global_mutex_trylock(exipc_mutex); if (APR_STATUS_IS_EBUSY(rs)) { apr_sleep(CAMPOUT); - } else if (APR_SUCCESS == rs) { + } + else if (APR_SUCCESS == rs) { gotlock = 1; break; /* Get out of the loop */ - } else if (APR_STATUS_IS_ENOTIMPL(rs)) { + } + else if (APR_STATUS_IS_ENOTIMPL(rs)) { /* If it's not implemented, just hang in the mutex. */ startcamp = apr_time_now(); rs = apr_global_mutex_lock(exipc_mutex); @@ -259,21 +262,23 @@ static int exipc_handler(request_rec *r) if (APR_SUCCESS == rs) { gotlock = 1; break; /* Out of the loop */ - } else { + } + else { /* Some error, log and bail */ ap_log_error(APLOG_MARK, APLOG_ERR, rs, r->server, "Child %ld failed to acquire lock", (long int)getpid()); break; /* Out of the loop without having the lock */ } - } else { + } + else { /* Some other error, log and bail */ ap_log_error(APLOG_MARK, APLOG_ERR, rs, r->server, "Child %ld failed to try and acquire lock", (long int)getpid()); break; /* Out of the loop without having the lock */ - } + /* * The only way to get to this point is if the trylock worked * and returned BUSY. So, bump the time and try again @@ -307,7 +312,8 @@ static int exipc_handler(request_rec *r) ap_rprintf(r, "Counter:%u\n", (unsigned int)base->counter); ap_rputs("\n", r); - } else { + } + else { /* * Send a page saying that we couldn't get the lock. Don't say * what the counter is, because without the lock the value could @@ -348,4 +354,3 @@ AP_DECLARE_MODULE(example_ipc) = { NULL, /* table of config file commands */ exipc_register_hooks /* register hooks */ }; - diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 92c3cd7fc0..f1ed708bff 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -3238,9 +3238,7 @@ static const char *cmd_rewritecond(cmd_parms *cmd, void *in_dconf, rewrite_server_conf *sconf; rewritecond_entry *newcond; ap_regex_t *regexp; - char *a1; - char *a2; - char *a3; + char *a1 = NULL, *a2 = NULL, *a3 = NULL; const char *err; sconf = ap_get_module_config(cmd->server->module_config, &rewrite_module); @@ -3657,9 +3655,7 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf, rewrite_server_conf *sconf; rewriterule_entry *newrule; ap_regex_t *regexp; - char *a1; - char *a2; - char *a3; + char *a1 = NULL, *a2 = NULL, *a3 = NULL; const char *err; sconf = ap_get_module_config(cmd->server->module_config, &rewrite_module); diff --git a/modules/proxy/mod_proxy_wstunnel.c b/modules/proxy/mod_proxy_wstunnel.c index 7c283b8e02..d75d00432d 100644 --- a/modules/proxy/mod_proxy_wstunnel.c +++ b/modules/proxy/mod_proxy_wstunnel.c @@ -183,7 +183,7 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r, return rv; } - buf = apr_pstrcat(p, "Upgrade: WebSocket", CRLF, "Connection: Upgrade", CRLF, CRLF, NULL); + buf = apr_pstrdup(p, "Upgrade: WebSocket" CRLF "Connection: Upgrade" CRLF CRLF); ap_xlate_proto_to_ascii(buf, strlen(buf)); e = apr_bucket_pool_create(buf, strlen(buf), p, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(header_brigade, e); diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 0b8b30c94d..b35278a746 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1159,7 +1159,7 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, c = strchr(uri, ':'); if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') - return "Bad syntax for a balancer name"; + return apr_psprintf(p, "Bad syntax for a balancer name (%s)", uri); /* remove path from uri */ if ((q = strchr(c + 3, '/'))) *q = '\0'; -- 2.40.0