u/logging: Use truncating snprintf utility for JSON log

When using the JSON logging mode, truncate log strings to
ensure they fit in the allocated message buffer

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2373>
This commit is contained in:
Jan Schmidt 2024-12-12 16:06:04 +11:00
parent efa6c5d149
commit e076de071a

View file

@ -339,7 +339,7 @@ log_as_json(const char *file, const char *func, enum u_logging_level level, cons
// Add message.
char msg_buf[LOG_BUFFER_SIZE];
vsprintf(msg_buf, format, args);
u_truncate_vsnprintf(msg_buf, LOG_BUFFER_SIZE, format, args);
cJSON_AddItemToObject(root, "message", cJSON_CreateString(msg_buf));
// Get string and print to stderr.