Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27dd513

Browse files
David AndrewsFelipe Zimmerle
David Andrews
authored and
Felipe Zimmerle
committed
Flip allocations that happen during initialization (typically) over to use non-global apr memory pools.
1 parent31d7fc6 commit27dd513

File tree

5 files changed

+130
-129
lines changed

5 files changed

+130
-129
lines changed

‎apache2/apache2_config.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
873873
*
874874
* ENH Probably do not want this done fully for chained rules.
875875
*/
876-
rule->actionset=msre_actionset_merge(modsecurity->msre,dcfg->tmp_default_actionset,
876+
rule->actionset=msre_actionset_merge(modsecurity->msre,cmd->pool,dcfg->tmp_default_actionset,
877877
rule->actionset,1);
878878

879879
/* Keep track of the parent action for "block" */
@@ -1068,7 +1068,7 @@ static const char *update_rule_action(cmd_parms *cmd, directory_config *dcfg,
10681068
}
10691069

10701070
/* Create a new actionset */
1071-
new_actionset=msre_actionset_create(modsecurity->msre,p2,&my_error_msg);
1071+
new_actionset=msre_actionset_create(modsecurity->msre,cmd->pool,p2,&my_error_msg);
10721072
if (new_actionset==NULL)returnFATAL_ERROR;
10731073
if (my_error_msg!=NULL)returnmy_error_msg;
10741074

@@ -1095,7 +1095,7 @@ static const char *update_rule_action(cmd_parms *cmd, directory_config *dcfg,
10951095

10961096
/* Merge new actions with the rule */
10971097
/* ENH: Will this leak the old actionset? */
1098-
rule->actionset=msre_actionset_merge(modsecurity->msre,rule->actionset,
1098+
rule->actionset=msre_actionset_merge(modsecurity->msre,cmd->pool,rule->actionset,
10991099
new_actionset,1);
11001100
msre_actionset_set_defaults(rule->actionset);
11011101

@@ -1477,7 +1477,7 @@ static const char *cmd_default_action(cmd_parms *cmd, void *_dcfg,
14771477
externmsc_engine*modsecurity;
14781478
char*my_error_msg=NULL;
14791479

1480-
dcfg->tmp_default_actionset=msre_actionset_create(modsecurity->msre,p1,&my_error_msg);
1480+
dcfg->tmp_default_actionset=msre_actionset_create(modsecurity->msre,cmd->pool,p1,&my_error_msg);
14811481
if (dcfg->tmp_default_actionset==NULL) {
14821482
if (my_error_msg!=NULL)returnmy_error_msg;
14831483
elsereturnFATAL_ERROR;

‎apache2/re.c‎

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static apr_status_t msre_parse_targets(msre_ruleset *ruleset, const char *text,
3838
staticchar*msre_generate_target_string(apr_pool_t*pool,msre_rule*rule);
3939
staticmsre_var*msre_create_var(msre_ruleset*ruleset,constchar*name,constchar*param,
4040
modsec_rec*msr,char**error_msg);
41-
staticmsre_action*msre_create_action(msre_engine*engine,constchar*name,
41+
staticmsre_action*msre_create_action(msre_engine*engine,apr_pool_t*mp,constchar*name,
4242
constchar*param,char**error_msg);
4343
staticapr_status_tmsre_rule_process(msre_rule*rule,modsec_rec*msr);
4444

@@ -769,7 +769,7 @@ static apr_status_t msre_parse_targets(msre_ruleset *ruleset, const char *text,
769769
* Creates msre_action instances by parsing the given string, placing
770770
* them into the supplied array.
771771
*/
772-
staticapr_status_tmsre_parse_actions(msre_engine*engine,msre_actionset*actionset,
772+
staticapr_status_tmsre_parse_actions(msre_engine*engine,apr_pool_t*mp,msre_actionset*actionset,
773773
constchar*text,char**error_msg)
774774
{
775775
constapr_array_header_t*tarr;
@@ -788,23 +788,23 @@ static apr_status_t msre_parse_actions(msre_engine *engine, msre_actionset *acti
788788

789789

790790
if (text==NULL) {
791-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
791+
*error_msg=apr_psprintf(mp,"Internal error: " \
792792
"msre_parse_actions, variable text is NULL");
793793
return-1;
794794
}
795795

796796
/* Extract name & value pairs first */
797-
vartable=apr_table_make(engine->mp,10);
797+
vartable=apr_table_make(mp,10);
798798
if (vartable==NULL) {
799-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
799+
*error_msg=apr_psprintf(mp,"Internal error: " \
800800
"msre_parse_actions, failed to create vartable");
801801

802802
return-1;
803803
}
804-
rc=msre_parse_generic(engine->mp,text,vartable,error_msg);
804+
rc=msre_parse_generic(mp,text,vartable,error_msg);
805805
if (rc<0) {
806806
if (*error_msg==NULL)
807-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
807+
*error_msg=apr_psprintf(mp,"Internal error: " \
808808
"msre_parse_actions, msre_parse_generic failed. Return " \
809809
"code: %d",rc);
810810

@@ -816,17 +816,17 @@ static apr_status_t msre_parse_actions(msre_engine *engine, msre_actionset *acti
816816
telts= (constapr_table_entry_t*)tarr->elts;
817817
for (i=0;i<tarr->nelts;i++) {
818818
/* Create action. */
819-
action=msre_create_action(engine,telts[i].key,telts[i].val,error_msg);
819+
action=msre_create_action(engine,mp,telts[i].key,telts[i].val,error_msg);
820820
if (action==NULL) {
821821
if (*error_msg==NULL)
822-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
822+
*error_msg=apr_psprintf(mp,"Internal error: " \
823823
"msre_parse_actions, msre_create_action failed.");
824824
return-1;
825825
}
826826

827827
/* Initialise action (option). */
828828
if (action->metadata->init!=NULL) {
829-
action->metadata->init(engine,actionset,action);
829+
action->metadata->init(engine,mp,actionset,action);
830830
}
831831

832832
msre_actionset_action_add(actionset,action);
@@ -895,14 +895,14 @@ msre_var *msre_create_var_ex(apr_pool_t *pool, msre_engine *engine, const char *
895895
/* Resolve variable */
896896
var->metadata=msre_resolve_var(engine,var->name);
897897
if (var->metadata==NULL) {
898-
*error_msg=apr_psprintf(engine->mp,"Unknown variable: %s",name);
898+
*error_msg=apr_psprintf(pool,"Unknown variable: %s",name);
899899
returnNULL;
900900
}
901901

902902
/* The counting operator "&" can only be used against collections. */
903903
if (var->is_counting) {
904904
if (var->metadata->type==VAR_SIMPLE) {
905-
*error_msg=apr_psprintf(engine->mp,"The & modificator does not apply to "
905+
*error_msg=apr_psprintf(pool,"The & modificator does not apply to "
906906
"non-collection variables.");
907907
returnNULL;
908908
}
@@ -911,15 +911,15 @@ msre_var *msre_create_var_ex(apr_pool_t *pool, msre_engine *engine, const char *
911911
/* Check the parameter. */
912912
if (varparam==NULL) {
913913
if (var->metadata->argc_min>0) {
914-
*error_msg=apr_psprintf(engine->mp,"Missing mandatory parameter for variable %s.",
914+
*error_msg=apr_psprintf(pool,"Missing mandatory parameter for variable %s.",
915915
name);
916916
returnNULL;
917917
}
918918
}else {/* Parameter present */
919919

920920
/* Do we allow a parameter? */
921921
if (var->metadata->argc_max==0) {
922-
*error_msg=apr_psprintf(engine->mp,"Variable %s does not support parameters.",
922+
*error_msg=apr_psprintf(pool,"Variable %s does not support parameters.",
923923
name);
924924
returnNULL;
925925
}
@@ -940,7 +940,7 @@ msre_var *msre_create_var_ex(apr_pool_t *pool, msre_engine *engine, const char *
940940
staticmsre_var*msre_create_var(msre_ruleset*ruleset,constchar*name,constchar*param,
941941
modsec_rec*msr,char**error_msg)
942942
{
943-
msre_var*var=msre_create_var_ex(ruleset->engine->mp,ruleset->engine,name,param,msr,error_msg);
943+
msre_var*var=msre_create_var_ex(ruleset->mp,ruleset->engine,name,param,msr,error_msg);
944944
if (var==NULL)returnNULL;
945945

946946
/* Validate & initialise variable */
@@ -957,7 +957,7 @@ static msre_var *msre_create_var(msre_ruleset *ruleset, const char *name, const
957957
/**
958958
* Creates a new action instance given its name and an (optional) parameter.
959959
*/
960-
msre_action*msre_create_action(msre_engine*engine,constchar*name,constchar*param,
960+
msre_action*msre_create_action(msre_engine*engine,apr_pool_t*mp,constchar*name,constchar*param,
961961
char**error_msg)
962962
{
963963
msre_action*action=NULL;
@@ -968,10 +968,10 @@ msre_action *msre_create_action(msre_engine *engine, const char *name, const cha
968968
*error_msg=NULL;
969969

970970

971-
action=apr_pcalloc(engine->mp,sizeof(msre_action));
971+
action=apr_pcalloc(mp,sizeof(msre_action));
972972

973973
if (action==NULL) {
974-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
974+
*error_msg=apr_psprintf(mp,"Internal error: " \
975975
"msre_create_action, not able to allocate action");
976976

977977
returnNULL;
@@ -980,28 +980,28 @@ msre_action *msre_create_action(msre_engine *engine, const char *name, const cha
980980
/* Resolve action */
981981
action->metadata=msre_resolve_action(engine,name);
982982
if (action->metadata==NULL) {
983-
*error_msg=apr_psprintf(engine->mp,"Unknown action: %s",name);
983+
*error_msg=apr_psprintf(mp,"Unknown action: %s",name);
984984
returnNULL;
985985
}
986986

987987
if (param==NULL) {/* Parameter not present */
988988
if (action->metadata->argc_min>0) {
989-
*error_msg=apr_psprintf(engine->mp,"Missing mandatory parameter for action %s",
989+
*error_msg=apr_psprintf(mp,"Missing mandatory parameter for action %s",
990990
name);
991991
returnNULL;
992992
}
993993
}else {/* Parameter present */
994994

995995
/* Should we allow the parameter? */
996996
if (action->metadata->argc_max==0) {
997-
*error_msg=apr_psprintf(engine->mp,"Extra parameter provided to action %s",name);
997+
*error_msg=apr_psprintf(mp,"Extra parameter provided to action %s",name);
998998
returnNULL;
999999
}
10001000

10011001
/* Handle +/- modificators */
10021002
if ((param[0]=='+')||(param[0]=='-')) {
10031003
if (action->metadata->allow_param_plusminus==0) {
1004-
*error_msg=apr_psprintf(engine->mp,
1004+
*error_msg=apr_psprintf(mp,
10051005
"Action %s does not allow +/- modificators.",name);
10061006
returnNULL;
10071007
}
@@ -1021,7 +1021,7 @@ msre_action *msre_create_action(msre_engine *engine, const char *name, const cha
10211021

10221022
/* Validate parameter */
10231023
if (action->metadata->validate!=NULL) {
1024-
*error_msg=action->metadata->validate(engine,action);
1024+
*error_msg=action->metadata->validate(engine,mp,action);
10251025
if (*error_msg!=NULL)returnNULL;
10261026
}
10271027
}
@@ -1164,7 +1164,7 @@ int msre_parse_generic(apr_pool_t *mp, const char *text, apr_table_t *vartable,
11641164
* Creates an actionset instance and (as an option) populates it by
11651165
* parsing the given string which contains a list of actions.
11661166
*/
1167-
msre_actionset*msre_actionset_create(msre_engine*engine,constchar*text,
1167+
msre_actionset*msre_actionset_create(msre_engine*engine,apr_pool_t*mp,constchar*text,
11681168
char**error_msg)
11691169
{
11701170
msre_actionset*actionset=NULL;
@@ -1175,18 +1175,18 @@ msre_actionset *msre_actionset_create(msre_engine *engine, const char *text,
11751175

11761176
*error_msg=NULL;
11771177

1178-
actionset= (msre_actionset*)apr_pcalloc(engine->mp,
1178+
actionset= (msre_actionset*)apr_pcalloc(mp,
11791179
sizeof(msre_actionset));
11801180

11811181
if (actionset==NULL) {
1182-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
1182+
*error_msg=apr_psprintf(mp,"Internal error: " \
11831183
"msre_actionset_create, not able to allocate msre_actionset");
11841184
returnNULL;
11851185
}
11861186

1187-
actionset->actions=apr_table_make(engine->mp,25);
1187+
actionset->actions=apr_table_make(mp,25);
11881188
if (actionset->actions==NULL) {
1189-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
1189+
*error_msg=apr_psprintf(mp,"Internal error: " \
11901190
"msre_actionset_create, not able to create actions table");
11911191
returnNULL;
11921192
}
@@ -1225,10 +1225,10 @@ msre_actionset *msre_actionset_create(msre_engine *engine, const char *text,
12251225

12261226
/* Parse the list of actions, if it's present */
12271227
if (text!=NULL) {
1228-
intret=msre_parse_actions(engine,actionset,text,error_msg);
1228+
intret=msre_parse_actions(engine,mp,actionset,text,error_msg);
12291229
if (ret<0) {
1230-
if (*error_msg==NULL)
1231-
*error_msg=apr_psprintf(engine->mp,"Internal error: " \
1230+
if (*error_msg==NULL)
1231+
*error_msg=apr_psprintf(mp,"Internal error: " \
12321232
"msre_actionset_create, msre_parse_actions failed " \
12331233
"without further information. Return code: %d",ret);
12341234
returnNULL;
@@ -1255,7 +1255,7 @@ static msre_actionset *msre_actionset_copy(apr_pool_t *mp, msre_actionset *orig)
12551255
/**
12561256
* Merges two actionsets into one.
12571257
*/
1258-
msre_actionset*msre_actionset_merge(msre_engine*engine,msre_actionset*parent,
1258+
msre_actionset*msre_actionset_merge(msre_engine*engine,apr_pool_t*mp,msre_actionset*parent,
12591259
msre_actionset*child,intinherit_by_default)
12601260
{
12611261
msre_actionset*merged=NULL;
@@ -1265,11 +1265,11 @@ msre_actionset *msre_actionset_merge(msre_engine *engine, msre_actionset *parent
12651265

12661266
if (inherit_by_default==0) {
12671267
/* There is nothing to merge in this case. */
1268-
returnmsre_actionset_copy(engine->mp,child);
1268+
returnmsre_actionset_copy(mp,child);
12691269
}
12701270

12711271
/* Start with a copy of the parent configuration. */
1272-
merged=msre_actionset_copy(engine->mp,parent);
1272+
merged=msre_actionset_copy(mp,parent);
12731273
if (merged==NULL)returnNULL;
12741274

12751275
if (child==NULL) {
@@ -1332,6 +1332,7 @@ msre_actionset *msre_actionset_merge(msre_engine *engine, msre_actionset *parent
13321332
msre_actionset*msre_actionset_create_default(msre_engine*engine) {
13331333
char*my_error_msg=NULL;
13341334
returnmsre_actionset_create(engine,
1335+
engine->mp,
13351336
"phase:2,log,auditlog,pass",
13361337
&my_error_msg);
13371338
}
@@ -2407,7 +2408,7 @@ msre_rule *msre_rule_create(msre_ruleset *ruleset, int type,
24072408
/* Parse actions */
24082409
if (actions!=NULL) {
24092410
/* Create per-rule actionset */
2410-
rule->actionset=msre_actionset_create(ruleset->engine,actions,&my_error_msg);
2411+
rule->actionset=msre_actionset_create(ruleset->engine,ruleset->mp,actions,&my_error_msg);
24112412
if (rule->actionset==NULL) {
24122413
*error_msg=apr_psprintf(ruleset->mp,"Error parsing actions: %s",my_error_msg);
24132414
returnNULL;
@@ -2451,7 +2452,7 @@ msre_rule *msre_rule_lua_create(msre_ruleset *ruleset,
24512452
/* Parse actions */
24522453
if (actions!=NULL) {
24532454
/* Create per-rule actionset */
2454-
rule->actionset=msre_actionset_create(ruleset->engine,actions,&my_error_msg);
2455+
rule->actionset=msre_actionset_create(ruleset->engine,ruleset->mp,actions,&my_error_msg);
24552456
if (rule->actionset==NULL) {
24562457
*error_msg=apr_psprintf(ruleset->mp,"Error parsing actions: %s",my_error_msg);
24572458
returnNULL;

‎apache2/re.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ void DSOLOCAL msre_engine_variable_register(msre_engine *engine, const char *nam
325325
fn_var_validate_tvalidate,fn_var_generate_tgenerate,
326326
unsignedintis_cacheable,unsignedintavailability);
327327

328-
msre_actionsetDSOLOCAL*msre_actionset_create(msre_engine*engine,constchar*text,
328+
msre_actionsetDSOLOCAL*msre_actionset_create(msre_engine*engine,apr_pool_t*mp,constchar*text,
329329
char**error_msg);
330330

331-
msre_actionsetDSOLOCAL*msre_actionset_merge(msre_engine*engine,msre_actionset*parent,
331+
msre_actionsetDSOLOCAL*msre_actionset_merge(msre_engine*engine,apr_pool_t*mp,msre_actionset*parent,
332332
msre_actionset*child,intinherit_by_default);
333333

334334
msre_actionsetDSOLOCAL*msre_actionset_create_default(msre_engine*engine);
@@ -337,8 +337,8 @@ void DSOLOCAL msre_actionset_set_defaults(msre_actionset *actionset);
337337

338338
voidDSOLOCALmsre_actionset_init(msre_actionset*actionset,msre_rule*rule);
339339

340-
typedefchar*(*fn_action_validate_t)(msre_engine*engine,msre_action*action);
341-
typedefapr_status_t (*fn_action_init_t)(msre_engine*engine,msre_actionset*actionset,msre_action*action);
340+
typedefchar*(*fn_action_validate_t)(msre_engine*engine,apr_pool_t*mp,msre_action*action);
341+
typedefapr_status_t (*fn_action_init_t)(msre_engine*engine,apr_pool_t*mp,msre_actionset*actionset,msre_action*action);
342342
typedefapr_status_t (*fn_action_execute_t)(modsec_rec*msr,apr_pool_t*mptmp,msre_rule*rule,msre_action*action);
343343

344344
#defineACTION_DISRUPTIVE 1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp