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 <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2024-02-29 12:24:21 +08:00 committed by Xiang Xiao
parent 9c51919a1a
commit bcbd092d3e

View file

@ -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;
}