Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
fix trace log message size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
waynz0r committed Mar 8, 2024
1 parent 707d1d8 commit 7a600f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion opa.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void opa_socket_context_free(opa_socket_context ctx)
opa_socket_context parse_opa_socket_eval_result(char *json)
{
JSON_Value *root_value = json_parse_string(json);
opa_socket_context ret = {};
opa_socket_context ret = {0};

if (root_value)
{
Expand Down
31 changes: 19 additions & 12 deletions trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ char *compose_log_message(const char *message, int n, va_list args)
{
int i;
va_list args_copy;
char *retval;
char *retval = NULL;

va_copy(args_copy, args);

Expand All @@ -189,20 +189,27 @@ char *compose_log_message(const char *message, int n, va_list args)
goto out;
}

int size = strlen(message) + 3;
for (i = 0; i < n; i++)
int size = strlen(message);
if (n > 0)
size += 3; // for the separator

for (i = 0; i < n; i += 2)
{
const char *arg = va_arg(args, const char *);
if (arg == NULL)
const char *var = va_arg(args, const char *);
const char *value = va_arg(args, const char *);

if (!var)
{
if (i % 2 == 0)
{
retval = ERR_PTR(-EINVAL);
goto out;
}
continue;
retval = ERR_PTR(-EINVAL);
goto out;
}

if (var && value)
{
size += strlen(var) + strlen(value) + 2; // +2 for []
if (i < n - 2)
size += 1; // +1 for a space
}
size += strlen(arg) + 1;
}

char *log_message = kzalloc(size + 1, GFP_KERNEL);
Expand Down

0 comments on commit 7a600f8

Please sign in to comment.