@@ -375,19 +375,12 @@ void dd_request_abort_redirect(void)
375375 ? ZSTR_VAL (_block_parameters -> security_response_id )
376376 : "" );
377377 } else {
378- zend_string * security_response_id = NULL ;
379- if (_block_parameters -> security_response_id ) {
380- security_response_id =
381- zend_string_dup (_block_parameters -> security_response_id , 0 );
382- }
383378 _emit_error ("Datadog blocked the request and attempted a redirection "
384379 "to %s. No action required. Security Response ID: %s" ,
385380 ZSTR_VAL (_block_parameters -> redirection_location ),
386- security_response_id ? ZSTR_VAL (security_response_id ) : "" );
387- if (security_response_id ) {
388- zend_string_release (security_response_id );
389- security_response_id = NULL ;
390- }
381+ _block_parameters -> security_response_id
382+ ? ZSTR_VAL (_block_parameters -> security_response_id )
383+ : "" );
391384 }
392385}
393386
@@ -469,18 +462,11 @@ void _request_abort_static_page(int response_code, int type)
469462 ? ZSTR_VAL (_block_parameters -> security_response_id )
470463 : "" );
471464 } else {
472- zend_string * security_response_id = NULL ;
473- if (_block_parameters -> security_response_id ) {
474- security_response_id =
475- zend_string_dup (_block_parameters -> security_response_id , 0 );
476- }
477465 _emit_error ("Datadog blocked the request and presented a static error "
478466 "page. No action required. Security Response ID: %s" ,
479- security_response_id ? ZSTR_VAL (security_response_id ) : "" );
480- if (security_response_id ) {
481- zend_string_release (security_response_id );
482- security_response_id = NULL ;
483- }
467+ _block_parameters -> security_response_id
468+ ? ZSTR_VAL (_block_parameters -> security_response_id )
469+ : "" );
484470 }
485471}
486472
@@ -566,20 +552,13 @@ static bool _abort_prelude(void)
566552 ? ZSTR_VAL (_block_parameters -> security_response_id )
567553 : "" );
568554 } else {
569- zend_string * security_response_id = NULL ;
570- if (_block_parameters -> security_response_id ) {
571- security_response_id =
572- zend_string_dup (_block_parameters -> security_response_id , 0 );
573- }
574555 _emit_error (
575556 "Datadog blocked the request, but the response has already "
576557 "been partially committed. No action required. Security "
577558 "Response ID: %s" ,
578- security_response_id ? ZSTR_VAL (security_response_id ) : "" );
579- if (security_response_id ) {
580- zend_string_release (security_response_id );
581- security_response_id = NULL ;
582- }
559+ _block_parameters -> security_response_id
560+ ? ZSTR_VAL (_block_parameters -> security_response_id )
561+ : "" );
583562 }
584563 return false;
585564 }
@@ -621,6 +600,22 @@ static void _emit_error(const char *format, ...)
621600
622601 va_list args ;
623602 va_start (args , format );
603+
604+ char buf [0x100 ];
605+ va_list args2 ;
606+ va_copy (args2 , args );
607+ int len = vsnprintf (buf , sizeof (buf ), format , args );
608+ char * msg = NULL ;
609+ bool free_msg = false;
610+ if (len > (int )sizeof (buf )) {
611+ msg = emalloc (len + 1 );
612+ len = vsnprintf (msg , len + 1 , format , args2 );
613+ free_msg = true;
614+ } else {
615+ msg = buf ;
616+ }
617+ va_end (args2 );
618+
624619 if (PG (during_request_startup )) {
625620 /* if emitting error during startup, RSHUTDOWN will not run (except fpm)
626621 * so we need to run the same logic from here */
@@ -637,15 +632,15 @@ static void _emit_error(const char *format, ...)
637632 /* fpm children exit if we throw an error at this point. So emit
638633 * only warning and use other means to prevent the script from
639634 * executing */
640- php_verror (NULL , "" , E_WARNING , format , args );
635+ php_verror (NULL , "" , E_WARNING , msg , args );
641636 va_end (args );
642637 // fpm doesn't try to run the script if it sees this null
643638 SG (request_info ).request_method = NULL ;
644639 return ;
645640 }
646641#ifdef FRANKENPHP_SUPPORT
647642 if (strcmp (sapi_module .name , "frankenphp" ) == 0 ) {
648- php_verror (NULL , "" , E_WARNING , format , args );
643+ php_verror (NULL , "" , E_WARNING , msg , args );
649644 va_end (args );
650645 _prepare_req_init_block ();
651646 return ;
@@ -676,14 +671,19 @@ static void _emit_error(const char *format, ...)
676671 {
677672 va_list args2 ;
678673 va_copy (args2 , args );
679- php_verror (NULL , "" , E_COMPILE_WARNING , format , args2 );
674+ php_verror (NULL , "" , E_COMPILE_WARNING , msg , args2 );
675+ if (free_msg ) {
676+ efree (msg );
677+ }
680678 va_end (args2 );
681679 }
682680
683681 // not enough: EG(error_handling) = EH_SUPPRESS;
684682 _suppress_error_reporting ();
685- php_verror (NULL , "" , E_ERROR , format , args );
686-
683+ php_verror (NULL , "" , E_ERROR , msg , args );
684+ if (free_msg ) {
685+ efree (msg );
686+ }
687687 va_end (args );
688688 __builtin_unreachable ();
689689}
0 commit comments