On Wed, Apr 05, 2023 at 05:03:23PM +0100, Bruce Richardson wrote:
> The json_snprintf function, used to add json characters on to a buffer,
> leaving the buffer unmodified in case of error, used a variable length
> array to store the data temporarily while checking for overflow. VLAs
> can be unsafe, and are unsupported by some compilers, so remove use of
> the VLA.
> 
> For the normal case where there is only a small amount of existing text
> in the buffer (<4 chars) to be preserved, save that off temporarily to a
> local array, and restore on error. To handle cases where there is more
> than a few characters in the buffer, we use the existing logic of doing
> the print to a temporary buffer initially and then copying. In this
> case, though we use malloc-allocated buffer rather than VLA.
> 
> Within the unit tests, the "telemetry_data_autotests" test cases - which
> mimic real telemetry use - all exercise the first path. The
> telemetry_json_autotest cases work directly with generating json, and
> use uninitialized buffers so also test the second, malloc-allocated
> buffer, cases.
> 
> Signed-off-by: Bruce Richardson <bruce.richard...@intel.com>
> 
> ---
Acked-by: Tyler Retzlaff <roret...@linux.microsoft.com>

Reply via email to