From b275204c877428f28272ecbbac84ba0d75552feb Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Sat, 25 Feb 2023 00:05:58 +0300 Subject: [PATCH] tools: check snprintf size argument to prevent potential overflow --- tools/shared.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/shared.c b/tools/shared.c index ee51b621..74a265ac 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -247,6 +247,10 @@ button_action_macro_to_str(struct ratbag_button *button) offset = snprintf(str, sizeof(str), "macro \"%s\":", name ? name : "UNKNOWN"); for (i = 0; i < MAX_MACRO_EVENTS; i++) { + if (offset < 0 || offset >= (int)sizeof(str) - offset) { + break; + } + enum ratbag_macro_event_type type = ratbag_button_macro_get_event_type(macro, i); int key = ratbag_button_macro_get_event_key(macro, i); int timeout = ratbag_button_macro_get_event_timeout(macro, i);