mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 21:34:07 +08:00
libc/fdcheck: cause system to panic when a double close occurs
There are many close calls in application without checking return value, and wrong code causes the same fd to be closed multi times, we should detect this situation and avoud effecting the fd in other threads. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -63,6 +63,7 @@ static uint8_t g_fdcheck_tag = 0;
|
||||
int fdcheck_restore(int val)
|
||||
{
|
||||
uint8_t tag_store;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
/* If val is a bare fd(0~255), we should return it directly */
|
||||
@@ -73,7 +74,7 @@ int fdcheck_restore(int val)
|
||||
return val;
|
||||
}
|
||||
|
||||
int ret = ioctl(fd, FIOC_GETTAG_FDCHECK, &tag_store);
|
||||
ret = ioctl(fd, FIOC_GETTAG_FDCHECK, &tag_store);
|
||||
if (ret >= 0)
|
||||
{
|
||||
uint8_t tag_expect = (val >> TAG_SHIFT) & TAG_MASK;
|
||||
@@ -84,6 +85,12 @@ int fdcheck_restore(int val)
|
||||
PANIC();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ferr("fd is bad, or fd have already been closed, errno:%d",
|
||||
get_errno());
|
||||
PANIC();
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user