Skip to content

Commit

Permalink
🔒️ fix malloc protection
Browse files Browse the repository at this point in the history
  • Loading branch information
froz42 committed Nov 4, 2023
1 parent 3869bfa commit f3b52aa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions srcs/syscall/param_log/log_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ static void buffer_add_char(buffer_t *buffer, char c)
{
buffer->size_buffer *= 2;
buffer->buffer = realloc(buffer->buffer, buffer->size_buffer);
if (buffer->buffer == NULL)
{
log_error("log_STRING", "realloc failed", true);
return;
}
}
buffer->buffer[buffer->index++] = c;
}
Expand All @@ -43,6 +48,11 @@ int log_remote_string(pid_t pid, char *remote_str, int max_size)
.size_buffer = DEFAULT_BUFFER_SIZE,
.index = 0,
};
if (buffer.buffer == NULL)
{
log_error("log_STRING", "malloc failed", true);
return 0;
}
char c = 1; // dummy value that will be overwritten by the first read
while (c != '\0')
{
Expand Down

0 comments on commit f3b52aa

Please sign in to comment.