From bcbd092d3ee1c2f27db0d3de04a02491b4c4cd02 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Thu, 29 Feb 2024 12:24:21 +0800 Subject: [PATCH] trace: fix trace dump crash After thread switching is triggered in an interrupt, two notes will be printed. If the buffer of 256 is not enough, it will cause overflow. Signed-off-by: yinshengkai --- system/trace/trace_dump.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/trace/trace_dump.c b/system/trace/trace_dump.c index b819b8cd31e..b78867a84c0 100644 --- a/system/trace/trace_dump.c +++ b/system/trace/trace_dump.c @@ -67,7 +67,7 @@ static void note_ioctl(int cmd, unsigned long arg) int trace_dump(FAR FILE *out) { - uint8_t tracedata[UCHAR_MAX]; + uint8_t tracedata[1024]; int ret; int fd; @@ -85,7 +85,12 @@ int trace_dump(FAR FILE *out) while (1) { ret = read(fd, tracedata, sizeof tracedata); - if (ret <= 0) + if (ret < 0 || ret > sizeof(tracedata)) + { + fprintf(stderr, "trace: read error: %d, errno:%d\n", ret, errno); + continue; + } + else if (ret == 0) { break; }