Thread (121 messages) 121 messages, 10 authors, 2021-11-04

[dpdk-dev] [v7, 5/6] telemetry: fix json output buffer size

From: Gowrishankar Muthukrishnan <hidden>
Date: 2021-09-08 17:04:02
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

Fix json output buffer size for a single largest value.

Fixes: 52af6ccb2b39 ("telemetry: add utility functions for creating JSON")

Signed-off-by: Gowrishankar Muthukrishnan <redacted>
Change-Id: Ida314114b654b5085244a659eb08b22969339856
---
 lib/telemetry/telemetry_json.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h
index ad270b9b30..ba2fde34cb 100644
--- a/lib/telemetry/telemetry_json.h
+++ b/lib/telemetry/telemetry_json.h
@@ -9,6 +9,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <rte_common.h>
+#include <rte_telemetry.h>
 
 /**
  * @file
@@ -23,13 +24,15 @@
  * @internal
  * Copies a value into a buffer if the buffer has enough available space.
  * Nothing written to buffer if an overflow ocurs.
- * This function is not for use for values larger than 1k.
+ * Size of buffer is (single largest value - 6), where at least 6 chars
+ * would have been used for creating json dict i.e '{"x": ... }'.
+ * This function is not for use for values larger than this buffer size.
  */
 __rte_format_printf(3, 4)
 static inline int
 __json_snprintf(char *buf, const int len, const char *format, ...)
 {
-	char tmp[1024];
+	char tmp[RTE_TEL_MAX_SINGLE_STRING_LEN - 6];
 	va_list ap;
 	int ret;
 
-- 
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help