Skip to content

Commit 193c190

Browse files
committed
Fix code
1 parent 0183e69 commit 193c190

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

appsec/src/extension/request_abort.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,18 @@ static void _emit_error(const char *format, ...)
625625
char *msg = NULL;
626626
bool free_msg = false;
627627
if (len >= (int)sizeof(buf)) {
628-
msg = safe_emalloc(len + 1, 1, 0);
629-
vsnprintf(msg, len + 1, format, args2);
630-
free_msg = true;
631-
} else {
628+
msg = safe_emalloc(len, 1, 0);
629+
if (vsnprintf(msg, len + 1, format, args2) < 0) {
630+
char default_msg[] = "Datadog blocked the request.";
631+
msg = default_msg;
632+
} else {
633+
free_msg = true;
634+
}
635+
} else if (len >= 0) {
632636
msg = buf;
637+
} else {
638+
char default_msg[] = "Datadog blocked the request.";
639+
msg = default_msg;
633640
}
634641
va_end(args2);
635642
va_end(args);
@@ -661,6 +668,9 @@ static void _emit_error(const char *format, ...)
661668
#ifdef FRANKENPHP_SUPPORT
662669
if (strcmp(sapi_module.name, "frankenphp") == 0) {
663670
_php_verror(E_WARNING, "%s", msg);
671+
if (free_msg) {
672+
efree(msg);
673+
}
664674
_prepare_req_init_block();
665675
return;
666676
}

0 commit comments

Comments
 (0)