@@ -434,7 +434,7 @@ void _request_abort_static_page(int response_code, int type)
434434 content_type = JSON_CONTENT_TYPE ;
435435 body = _get_json_blocking_template ();
436436 } else {
437- mlog (dd_log_error , "unknown response type (bug) %d" , response_type );
437+ mlog (dd_log_error , " response type (bug) %d" , response_type );
438438 return ;
439439 }
440440
@@ -592,6 +592,15 @@ static void _force_destroy_output_handlers(void)
592592static void _run_rshutdowns (void );
593593static void _suppress_error_reporting (void );
594594
595+ ATTR_FORMAT (2 , 3 )
596+ static void _php_verror (int type , const char * format , ...)
597+ {
598+ va_list args ;
599+ va_start (args , format );
600+ php_verror (NULL , "" , type , format , args );
601+ va_end (args );
602+ }
603+
595604ATTR_FORMAT (1 , 2 )
596605static void _emit_error (const char * format , ...)
597606{
@@ -600,20 +609,22 @@ static void _emit_error(const char *format, ...)
600609
601610 va_list args ;
602611 va_start (args , format );
603- char buf [0x100 ];
604612 va_list args2 ;
605613 va_copy (args2 , args );
614+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
615+ char buf [512 ];
606616 int len = vsnprintf (buf , sizeof (buf ), format , args );
607617 char * msg = NULL ;
608618 bool free_msg = false;
609- if (len > (int )sizeof (buf )) {
610- msg = emalloc (len + 1 );
611- len = vsnprintf (msg , len + 1 , format , args2 );
619+ if (len >= (int )sizeof (buf )) {
620+ msg = safe_emalloc (len + 1 , 1 , 0 );
621+ vsnprintf (msg , len + 1 , format , args2 );
612622 free_msg = true;
613623 } else {
614624 msg = buf ;
615625 }
616626 va_end (args2 );
627+ va_end (args );
617628
618629 if (PG (during_request_startup )) {
619630 /* if emitting error during startup, RSHUTDOWN will not run (except fpm)
@@ -631,19 +642,17 @@ static void _emit_error(const char *format, ...)
631642 /* fpm children exit if we throw an error at this point. So emit
632643 * only warning and use other means to prevent the script from
633644 * executing */
634- php_verror ( NULL , "" , E_WARNING , msg , args );
645+ _php_verror ( E_WARNING , "%s " , msg );
635646 if (free_msg ) {
636647 efree (msg );
637648 }
638- va_end (args );
639649 // fpm doesn't try to run the script if it sees this null
640650 SG (request_info ).request_method = NULL ;
641651 return ;
642652 }
643653#ifdef FRANKENPHP_SUPPORT
644654 if (strcmp (sapi_module .name , "frankenphp" ) == 0 ) {
645- php_verror (NULL , "" , E_WARNING , msg , args );
646- va_end (args );
655+ _php_verror (E_WARNING , "%s" , msg );
647656 _prepare_req_init_block ();
648657 return ;
649658 }
@@ -671,22 +680,15 @@ static void _emit_error(const char *format, ...)
671680 * be a possibility, but it bypasses the value of error_reporting and is
672681 * always logged */
673682 {
674- va_list args2 ;
675- va_copy (args2 , args );
676- php_verror (NULL , "" , E_COMPILE_WARNING , msg , args2 );
677- if (free_msg ) {
678- efree (msg );
679- }
680- va_end (args2 );
683+ _php_verror (E_COMPILE_WARNING , "%s" , msg );
681684 }
682685
683686 // not enough: EG(error_handling) = EH_SUPPRESS;
684687 _suppress_error_reporting ();
685- php_verror ( NULL , "" , E_ERROR , msg , args );
688+ _php_verror ( E_ERROR , "%s " , msg );
686689 if (free_msg ) {
687690 efree (msg );
688691 }
689- va_end (args );
690692 __builtin_unreachable ();
691693}
692694
0 commit comments