This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e2148c513ba363f8826dfdda3222e0f00fb7a986 Author: dongjiuzhu1 <dongjiuz...@xiaomi.com> AuthorDate: Mon Mar 10 14:09:59 2025 +0800 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 <dongjiuz...@xiaomi.com> --- libs/libc/misc/lib_fdcheck.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/libc/misc/lib_fdcheck.c b/libs/libc/misc/lib_fdcheck.c index f14d3b751d..2119eb1181 100644 --- a/libs/libc/misc/lib_fdcheck.c +++ b/libs/libc/misc/lib_fdcheck.c @@ -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; }