--- parser3/src/classes/op.C 2026/09/25 17:03:52 1.283 +++ parser3/src/classes/op.C 2026/10/13 20:02:00 1.286 @@ -23,7 +23,7 @@ #include "syslog.h" #endif -volatile const char * IDENT_OP_C="$Id: op.C,v 1.283 2026/09/25 17:03:52 moko Exp $"; +volatile const char * IDENT_OP_C="$Id: op.C,v 1.286 2026/10/13 20:02:00 moko Exp $"; // defines @@ -57,40 +57,6 @@ static const String exception_var_name(E #define CACHE_EXCEPTION_HANDLED_CACHE_NAME "cache" -// helpers - -class Untaint_lang_name2enum: public HashString { -public: - Untaint_lang_name2enum() { - #define ULN(name, LANG) put(name, (value_type)(String::L_##LANG)); - ULN("clean", CLEAN); - ULN("as-is", AS_IS); - ULN("optimized-as-is", AS_IS|String::L_OPTIMIZE_BIT); - ULN("file-spec", FILE_SPEC); - ULN("http-header", HTTP_HEADER); - ULN("mail-header", MAIL_HEADER); - ULN("uri", URI); - ULN("sql", SQL); - ULN("js", JS); - ULN("xml", XML); - ULN("optimized-xml", XML|String::L_OPTIMIZE_BIT); - ULN("html", HTML); - ULN("optimized-html", HTML|String::L_OPTIMIZE_BIT); - ULN("regex", REGEX); - ULN("parser-code", PARSER_CODE); - ULN("json", JSON); - #undef ULN - } - - static Untaint_lang_name2enum &instance(){ - static Untaint_lang_name2enum *singleton=NULL; - if(!singleton) - singleton=new Untaint_lang_name2enum; - return *singleton; - } - -}; - // methods static void _if(Request& r, MethodParams& params) { @@ -109,19 +75,12 @@ static void _if(Request& r, MethodParams r.process_write(params[i]); } -String::Language get_untaint_lang(const String& lang_name){ - String::Language lang=Untaint_lang_name2enum::instance().get(lang_name); - if(!lang) - throw Exception(PARSER_RUNTIME, &lang_name, "invalid taint language"); - return lang; -} - static void _untaint(Request& r, MethodParams& params) { String::Language lang; if(params.count()==1) lang=String::L_AS_IS; // mark as simply 'as-is'. useful in html from sql else - lang=get_untaint_lang(params.as_string(0, "lang must be string")); + lang=String::name2lang(params.as_string(0, "lang must be string")); Value& vbody=params.as_junction(params.count()-1, "body must be code"); Value& result=r.process(vbody); @@ -139,7 +98,7 @@ static void _taint(Request& r, MethodPar if(params.count()==1) lang=String::L_TAINTED; // mark as simply 'tainted'. useful in table:create else - lang=get_untaint_lang(params.as_string(0, "lang must be string")); + lang=String::name2lang(params.as_string(0, "lang must be string")); { Value& vbody=params.as_no_junction(params.count()-1, "body must not be code"); @@ -150,7 +109,7 @@ static void _taint(Request& r, MethodPar } static void _apply_taint(Request& r, MethodParams& params) { - String::Language lang=params.count()==1 ? String::L_AS_IS : get_untaint_lang(params.as_string(0, "lang must be string")); + String::Language lang=params.count()==1 ? String::L_AS_IS : String::name2lang(params.as_string(0, "lang must be string")); const String &sbody=params.as_string(params.count()-1, "body must be string"); String::Body result_body=sbody.cstr_to_string_body_untaint(lang, r.connection(false), &r.charsets); r.write(*new String(result_body, String::L_AS_IS)); @@ -548,6 +507,8 @@ static Try_catch_result try_catch(Reques try { result.processed_code=body_code(r, info); + } catch(const Recursion_limit_exception&) { + rethrow; } catch(const Exception& e) { size_t trace_bottom=r.exception_trace.bottom_index(); size_t trace_top=r.exception_trace.top_index(); @@ -555,6 +516,7 @@ static Try_catch_result try_catch(Reques VException& details=*new VException(r, e); try_context.restore(); // restoring try-context for catch code + r.recursion_limit_try_restore(); // here to allow "endless" recursion in catch r.exception_trace.set_bottom_index(trace_top); // keep the original trace occupied; errors in catch start after it @@ -576,8 +538,8 @@ static Try_catch_result try_catch(Reques bhandled=vhandled->as_bool(); } } catch(...) { - // restore execution for finally, but keep new error trace. - try_context.restore(); + try_context.restore(); // restore execution for finally, but keep new error trace. + r.recursion_limit_try_restore(); // here to allow "endless" recursion in finally details.expire_trace(); rethrow; } @@ -587,6 +549,7 @@ static Try_catch_result try_catch(Reques r.exception_trace.set_range(trace_bottom, trace_top); rethrow; } + r.exception_trace.set_range(trace_start, trace_start); } @@ -841,6 +804,8 @@ static void _try_operator(Request& r, Me try{ // process try and catch code result=try_catch(r, process_try_body_code, &body_code, &catch_code); + } catch(const Recursion_limit_exception&) { + rethrow; } catch(...){ // process finally code but ignore the result if(finally_code){