--- parser3/src/main/pa_request.C 2016/09/21 15:35:11 1.359 +++ parser3/src/main/pa_request.C 2016/10/09 21:32:19 1.362 @@ -32,7 +32,7 @@ #include "pa_vconsole.h" #include "pa_vdate.h" -volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.359 2016/09/21 15:35:11 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; +volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.362 2016/10/09 21:32:19 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts @@ -44,6 +44,9 @@ const char* UNHANDLED_EXCEPTION_CONTENT_ /// content type of response when no $MAIN:defaults.content-type defined const char* DEFAULT_CONTENT_TYPE="text/html"; +const uint EXECUTE_RECOURSION_LIMIT=1000; +const uint LOOP_LIMIT=20000; + // defines for globals #define MAIN_METHOD_NAME "main" @@ -64,12 +67,18 @@ const String exception_source_part_name( const String exception_comment_part_name(EXCEPTION_COMMENT_PART_NAME); const String exception_handled_part_name(EXCEPTION_HANDLED_PART_NAME); +int pa_execute_recoursion_limit=EXECUTE_RECOURSION_LIMIT; +int pa_loop_limit=LOOP_LIMIT; + // defines for statics #define CHARSETS_NAME "CHARSETS" #define MIME_TYPES_NAME "MIME-TYPES" #define STRICT_VARS_NAME "STRICT-VARS" #define PROTOTYPE_NAME "OBJECT-PROTOTYPE" +#define LIMITS_NAME "LIMITS" +#define RECOURSION_LIMIT_NAME "max_recoursion" +#define LOOP_LIMIT_NAME "max_loop" #define CONF_METHOD_NAME "conf" #define POST_PROCESS_METHOD_NAME "postprocess" #define CLASS_PATH_NAME "CLASS_PATH" @@ -85,6 +94,10 @@ static const String main_class_name(MAIN static const String mime_types_name(MIME_TYPES_NAME); static const String strict_vars_name(STRICT_VARS_NAME); static const String prototype_name(PROTOTYPE_NAME); +static const String limits_name(LIMITS_NAME); +static const String recoursion_limit_name(RECOURSION_LIMIT_NAME); +static const String loop_limit_name(LOOP_LIMIT_NAME); + static const String conf_method_name(CONF_METHOD_NAME); static const String post_process_method_name(POST_PROCESS_METHOD_NAME); static const String class_path_name(CLASS_PATH_NAME); @@ -265,6 +278,28 @@ void Request::configure_admin(VStateless } #endif + Value* limits=conf_class.get_element(limits_name); + + pa_loop_limit=LOOP_LIMIT; + if(limits) + if(Value* loop_limit=limits->get_element(loop_limit_name)) { + if(loop_limit->is_evaluated_expr()) { + pa_loop_limit=loop_limit->as_int(); + if(pa_loop_limit==0) pa_loop_limit=INT_MAX; + } else + throw Exception(PARSER_RUNTIME, 0, "$" MAIN_CLASS_NAME ":" LOOP_LIMIT_NAME " must be int"); + } + + pa_execute_recoursion_limit=EXECUTE_RECOURSION_LIMIT; + if(limits) + if(Value* recoursion_limit=limits->get_element(recoursion_limit_name)) { + if(recoursion_limit->is_evaluated_expr()) { + pa_execute_recoursion_limit=recoursion_limit->as_int(); + if(pa_execute_recoursion_limit==0) pa_execute_recoursion_limit=INT_MAX; + } else + throw Exception(PARSER_RUNTIME, 0, "$" MAIN_CLASS_NAME ":" RECOURSION_LIMIT_NAME " must be int"); + } + // configure method_frame options // until someone with less privileges have overriden them methoded_array().configure_admin(*this); @@ -413,7 +448,7 @@ void Request::core(const char* config_fi frame.store_params(&body_value, 1); execute_method(frame); - body_value=&frame.result().as_value(); + body_value=&frame.result(); } VFile* body_file=body_value->as_vfile(flang, &charsets);