Skip to content

Commit 01e8e23

Browse files
fix: add overflow check for calloc operation in ggml_log_internal_v
Co-Authored-By: Jake Cosme <[email protected]>
1 parent 8f03ebe commit 01e8e23

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ggml/src/ggml.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ static void ggml_log_internal_v(enum ggml_log_level level, const char * format,
259259
if (len < 128) {
260260
g_logger_state.log_callback(level, buffer, g_logger_state.log_callback_user_data);
261261
} else {
262+
if (len < 0 || len >= INT_MAX) {
263+
return; // Invalid length from vsnprintf
264+
}
262265
char * buffer2 = (char *) calloc(len + 1, sizeof(char));
266+
if (!buffer2) {
267+
return; // Allocation failed
268+
}
263269
vsnprintf(buffer2, len + 1, format, args_copy);
264270
buffer2[len] = 0;
265271
g_logger_state.log_callback(level, buffer2, g_logger_state.log_callback_user_data);

0 commit comments

Comments
 (0)