From 2357f2b10dc2cf06830264f4ab94fb23a53e7176 Mon Sep 17 00:00:00 2001 From: nashit hayyat Date: Thu, 27 Aug 2026 13:44:14 +0530 Subject: [PATCH] clamp vsnprintf result before copying in log_printf --- src/runtime/hexagon_remote/qurt/log.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/runtime/hexagon_remote/qurt/log.cpp b/src/runtime/hexagon_remote/qurt/log.cpp index 18b97e380bd4..2283e3d9af70 100644 --- a/src/runtime/hexagon_remote/qurt/log.cpp +++ b/src/runtime/hexagon_remote/qurt/log.cpp @@ -66,6 +66,14 @@ void log_printf(const char *fmt, ...) { va_start(ap, fmt); int message_size = vsnprintf(message, sizeof(message) - 1, fmt, ap); va_end(ap); + if (message_size < 0) { + return; + } + // vsnprintf returns the length the message would have been, not the number + // of bytes written, so clamp to what actually fit before copying it out. + if (message_size > (int)sizeof(message) - 1) { + message_size = sizeof(message) - 1; + } global_log.write(message, message_size); }