telemetry: fix JSON string formatter

Message ID 20230525072035.2512566-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series telemetry: fix JSON string formatter |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

David Marchand May 25, 2023, 7:20 a.m. UTC
  For large strings, we were incorrectly copying uninitialised data to the
output buffer.
Restore previous code.

Fixes: a515b7204e28 ("telemetry: remove VLA in JSON string formatter")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/telemetry/telemetry_json.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Bruce Richardson May 25, 2023, 8:30 a.m. UTC | #1
On Thu, May 25, 2023 at 09:20:35AM +0200, David Marchand wrote:
> For large strings, we were incorrectly copying uninitialised data to the
> output buffer.
> Restore previous code.
> 
> Fixes: a515b7204e28 ("telemetry: remove VLA in JSON string formatter")
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon May 25, 2023, 8:38 a.m. UTC | #2
25/05/2023 10:30, Bruce Richardson:
> On Thu, May 25, 2023 at 09:20:35AM +0200, David Marchand wrote:
> > For large strings, we were incorrectly copying uninitialised data to the
> > output buffer.
> > Restore previous code.
> > 
> > Fixes: a515b7204e28 ("telemetry: remove VLA in JSON string formatter")
> > 
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks (and sorry for merging the commit triggering CI failures).
  

Patch

diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h
index 7999535848..7a246deacb 100644
--- a/lib/telemetry/telemetry_json.h
+++ b/lib/telemetry/telemetry_json.h
@@ -153,7 +153,7 @@  __json_format_str(char *buf, const int len, const char *prefix, const char *str,
 
 	ret = __json_format_str_to_buf(tmp, len, prefix, str, suffix);
 	if (ret > 0)
-		strcpy(buf, saved);
+		strcpy(buf, tmp);
 
 	free(tmp);
 	return ret;