Skip to content

Commit 1f57085

Browse files
committed
Fix issue when compile warning
1 parent c837f84 commit 1f57085

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

appsec/src/extension/request_abort.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
592592
static void _run_rshutdowns(void);
593593
static 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+
595604
ATTR_FORMAT(1, 2)
596605
static void _emit_error(const char *format, ...)
597606
{
@@ -600,20 +609,21 @@ 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+
char buf[0x100];
606615
int len = vsnprintf(buf, sizeof(buf), format, args);
607616
char *msg = NULL;
608617
bool free_msg = false;
609-
if (len > (int)sizeof(buf)) {
610-
msg = emalloc(len + 1);
618+
if (len >= (int)sizeof(buf)) {
619+
msg = safe_emalloc(len + 1, 1, 0);
611620
len = vsnprintf(msg, len + 1, format, args2);
612621
free_msg = true;
613622
} else {
614623
msg = buf;
615624
}
616625
va_end(args2);
626+
va_end(args);
617627

618628
if (PG(during_request_startup)) {
619629
/* if emitting error during startup, RSHUTDOWN will not run (except fpm)
@@ -631,19 +641,17 @@ static void _emit_error(const char *format, ...)
631641
/* fpm children exit if we throw an error at this point. So emit
632642
* only warning and use other means to prevent the script from
633643
* executing */
634-
php_verror(NULL, "", E_WARNING, msg, args);
644+
_php_verror(E_WARNING, "%s", msg);
635645
if (free_msg) {
636646
efree(msg);
637647
}
638-
va_end(args);
639648
// fpm doesn't try to run the script if it sees this null
640649
SG(request_info).request_method = NULL;
641650
return;
642651
}
643652
#ifdef FRANKENPHP_SUPPORT
644653
if (strcmp(sapi_module.name, "frankenphp") == 0) {
645-
php_verror(NULL, "", E_WARNING, msg, args);
646-
va_end(args);
654+
_php_verror(E_WARNING, "%s", msg);
647655
_prepare_req_init_block();
648656
return;
649657
}
@@ -671,22 +679,15 @@ static void _emit_error(const char *format, ...)
671679
* be a possibility, but it bypasses the value of error_reporting and is
672680
* always logged */
673681
{
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);
682+
_php_verror(E_COMPILE_WARNING, "%s", msg);
681683
}
682684

683685
// not enough: EG(error_handling) = EH_SUPPRESS;
684686
_suppress_error_reporting();
685-
php_verror(NULL, "", E_ERROR, msg, args);
687+
_php_verror(E_ERROR, "%s", msg);
686688
if (free_msg) {
687689
efree(msg);
688690
}
689-
va_end(args);
690691
__builtin_unreachable();
691692
}
692693

0 commit comments

Comments
 (0)