From 2908491c7efee5e14e880aa7a49ee6e5f098a24d Mon Sep 17 00:00:00 2001 From: Celeste Liu Date: Tue, 17 Sep 2024 14:30:46 +0800 Subject: [PATCH] monitor: fix buffer overflow when terminal width > 255 In current code, we create line buffer with size 256, which can contains 255 ASCII characters. But in modern system, terminal can have larger width. It may cause buffer overflow in snprintf() text. limits.h provides constant LINE_MAX. {LINE_MAX} Unless otherwise noted, the maximum length, in bytes, of a utility's input line (either standard input or another file), when the utility is described as processing text files. The length includes room for the trailing . Minimum Acceptable Value: {_POSIX2_LINE_MAX} --- monitor/packet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor/packet.c b/monitor/packet.c index c2599fe68..32a440bbe 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "lib/bluetooth.h" #include "lib/uuid.h" @@ -376,7 +377,7 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident, const char *text, const char *extra) { int col = num_columns(); - char line[256], ts_str[96], pid_str[140]; + char line[LINE_MAX], ts_str[96], pid_str[140]; int n, ts_len = 0, ts_pos = 0, len = 0, pos = 0; static size_t last_frame; -- 2.47.3