Skip to content

Commit

Permalink
trace: fix trace dump crash
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Gary-Hobson authored and xiaoxiang781216 committed Oct 15, 2024
1 parent 9c51919 commit bcbd092
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions system/trace/trace_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down

0 comments on commit bcbd092

Please sign in to comment.