Skip to content

Commit

Permalink
telemetry: fix autotest on Alpine
Browse files Browse the repository at this point in the history
[ upstream commit 6ffce64857216344f02ee88d92cb69ee241b3c7b ]

On Alpine linux, the telemetry_data_autotest was failing for the
test where we had dictionaries embedded in other dictionaries up
to three levels deep. Indications are that this issue is due to
excess data being stored on the stack, so replace stack-allocated
buffer data with dynamically allocated data in the case where we
are doing recursive processing of telemetry data structures into
json.

Bugzilla ID: 1177
Fixes: c933bb5 ("telemetry: support array values in data object")
Fixes: d2671e6 ("telemetry: support dict of dicts")

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  • Loading branch information
bruce-richardson authored and kevintraynor committed Jul 11, 2023
1 parent 16e1d05 commit c95d48b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
break;
case RTE_TEL_CONTAINER:
{
char temp[buf_len];
char *temp = malloc(buf_len);
if (temp == NULL)
break;
*temp = '\0'; /* ensure valid string */

const struct container *cont =
&v->value.container;
if (container_to_json(cont->data,
Expand All @@ -208,6 +212,7 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
v->name, temp);
if (!cont->keep)
rte_tel_data_free(cont->data);
free(temp);
break;
}
}
Expand Down Expand Up @@ -264,7 +269,11 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
break;
case RTE_TEL_CONTAINER:
{
char temp[buf_len];
char *temp = malloc(buf_len);
if (temp == NULL)
break;
*temp = '\0'; /* ensure valid string */

const struct container *cont =
&v->value.container;
if (container_to_json(cont->data,
Expand All @@ -275,6 +284,7 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
v->name, temp);
if (!cont->keep)
rte_tel_data_free(cont->data);
free(temp);
}
}
}
Expand Down Expand Up @@ -306,7 +316,11 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
buf_len, used,
d->data.array[i].u64val);
else if (d->type == RTE_TEL_ARRAY_CONTAINER) {
char temp[buf_len];
char *temp = malloc(buf_len);
if (temp == NULL)
break;
*temp = '\0'; /* ensure valid string */

const struct container *rec_data =
&d->data.array[i].container;
if (container_to_json(rec_data->data,
Expand All @@ -316,6 +330,7 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
buf_len, used, temp);
if (!rec_data->keep)
rte_tel_data_free(rec_data->data);
free(temp);
}
used += prefix_used;
used += strlcat(out_buf + used, "}", sizeof(out_buf) - used);
Expand Down

0 comments on commit c95d48b

Please sign in to comment.