@@ -312,6 +312,24 @@ static apr_status_t modsecurity_request_body_store_memory(modsec_rec *msr,
312312 return 1 ;
313313}
314314
315+ /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
316+ static void modsecurity_request_body_enable_partial_processing_for_no_files_length (modsec_rec * msr ,
317+ apr_size_t * length , const char * reqbody_processor )
318+ {
319+ /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
320+ if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
321+ && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
322+ {
323+ * length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
324+ if (msr -> txcfg -> debuglog_level >= 9 ) {
325+ msr_log (msr , 9 , "%s: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
326+ reqbody_processor ,
327+ msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
328+ }
329+ modsecurity_request_body_enable_partial_processing (msr );
330+ }
331+ }
332+
315333/**
316334 * Stores one chunk of request body data. Returns -1 on error.
317335 */
@@ -361,18 +379,7 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
361379 else if (strcmp (msr -> msc_reqbody_processor , "XML" ) == 0 ) {
362380 /* Increase per-request data length counter. */
363381 msr -> msc_reqbody_no_files_length += length ;
364-
365- /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
366- if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
367- && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
368- {
369- length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
370- if (msr -> txcfg -> debuglog_level >= 9 ) {
371- msr_log (msr , 9 , "XML: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
372- msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
373- }
374- modsecurity_request_body_enable_partial_processing (msr );
375- }
382+ modsecurity_request_body_enable_partial_processing_for_no_files_length (msr , & length , "XML" );
376383
377384 /* Process data as XML. */
378385 if (xml_process_chunk (msr , data , length , & my_error_msg ) < 0 ) {
@@ -385,18 +392,7 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
385392 else if (strcmp (msr -> msc_reqbody_processor , "JSON" ) == 0 ) {
386393 /* Increase per-request data length counter. */
387394 msr -> msc_reqbody_no_files_length += length ;
388-
389- /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
390- if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
391- && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
392- {
393- length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
394- if (msr -> txcfg -> debuglog_level >= 9 ) {
395- msr_log (msr , 9 , "JSON: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
396- msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
397- }
398- modsecurity_request_body_enable_partial_processing (msr );
399- }
395+ modsecurity_request_body_enable_partial_processing_for_no_files_length (msr , & length , "JSON" );
400396
401397 /* Process data as JSON. */
402398#ifdef WITH_YAJL
@@ -416,18 +412,7 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
416412 else if (strcmp (msr -> msc_reqbody_processor , "URLENCODED" ) == 0 ) {
417413 /* Increase per-request data length counter. */
418414 msr -> msc_reqbody_no_files_length += length ;
419-
420- /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
421- if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
422- && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
423- {
424- length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
425- if (msr -> txcfg -> debuglog_level >= 9 ) {
426- msr_log (msr , 9 , "URLENCODED: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
427- msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
428- }
429- modsecurity_request_body_enable_partial_processing (msr );
430- }
415+ modsecurity_request_body_enable_partial_processing_for_no_files_length (msr , & length , "URLENCODED" );
431416
432417 /* Do nothing else, URLENCODED processor does not support streaming. */
433418 }
@@ -439,18 +424,7 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
439424 } else if (msr -> txcfg -> reqbody_buffering != REQUEST_BODY_FORCEBUF_OFF ) {
440425 /* Increase per-request data length counter if forcing buffering. */
441426 msr -> msc_reqbody_no_files_length += length ;
442-
443- /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
444- if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
445- && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
446- {
447- length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
448- if (msr -> txcfg -> debuglog_level >= 9 ) {
449- msr_log (msr , 9 , "forceBuf: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
450- msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
451- }
452- modsecurity_request_body_enable_partial_processing (msr );
453- }
427+ modsecurity_request_body_enable_partial_processing_for_no_files_length (msr , & length , "forceBuf" );
454428 }
455429
456430 /* Check that we are not over the request body no files limit. */
0 commit comments