[Problem Description]
When assigning name to rt_object, strncpy() uses size equal to RT_NAME_MAX,
which causes missing null-terminator and overflows into adjacent 'type' field.
This corruption leads to unexpected system behavior.
[Problem Analysis]
The rt_object structure defines:
| char name[RT_NAME_MAX] | -> buffer
| rt_uint8_t type | -> adjacent field
Original code calculates size as:
size = end - first + 1;
if (size > RT_NAME_MAX) size = RT_NAME_MAX;
When size equals RT_NAME_MAX, strncpy() will copy exactly RT_NAME_MAX bytes
without adding terminating '\0', causing two issues:
1. name buffer is not null-terminated
2. The implicit null-byte writes beyond name[] into type field
[Solution]
Change boundary check from:
if (size > RT_NAME_MAX) size = RT_NAME_MAX;
to:
if (size >= RT_NAME_MAX) size = RT_NAME_MAX - 1;
This ensures:
1. Always leaves space for null-terminator
2. Prevents overflow into type field
3. Maintains maximum valid name length (RT_NAME_MAX-1 + '\0')
Signed-off-by: Liu Gui <kenneth.liu@sophgo.com>
Analysis: There is still an omission in the preprocessing control of
_control_rtc in 24b0a81 ("Add RT_USING_RTC conditional
compilation protection in ctimer.c")
Solution: Add RT_USING_RTC preprocessing control to missing
_control_rtc
Signed-off-by: Shicheng Chu <1468559561@qq.com>
Analysis: RT_USING_RTC preprocessing is used in 47cd52d ("修复不
使能 RT_USING_DEVICE 时编译报错") to control the reference of
rtdevice.h, as well as the implementation and call of _control_rtc,
but there are some omissions.
Solution: Add RT_USING_RTC preprocessing control to missing
_control_rtc
Signed-off-by: Shicheng Chu <1468559561@qq.com>
Reviewed-by: Chen Wang <unicorn_wang@outlook.com>
* support period time
* enable multiple ktimer
* mv set delay_cnt to hrtimer_start
* add ktime debug info
* change current_irq_begin to local var
* fix bug: setting current timer and setting timeout in driver aren't atomicly
* create->init
* refactoring ktime
* [thread] Add rt_thread_close()
This patch introduces a new function `rt_thread_close()` to enhances the
usability and maintainability by providing a dedicated mechanism for
closing threads.
- A new function `rt_thread_close()` is added to the API, providing a
standardized approach for closing threads.
- The `rt_thread_close()` function removes a thread from the thread
queue, updates its status to indicate closure, and performs the thread
timer detaching which is a embedded timer in thread object.
- Additionally, the `rt_thread_detach()` function is modified to utilize
`rt_thread_close()` internally, streamlining the thread detachment
process.
Signed-off-by: Shell <smokewood@qq.com>
modified: components/libc/posix/io/aio/aio.h Align comments within the aiocb structure
modified: components/libc/posix/io/epoll/epoll.c Add comments for all functions and members within structure members
modified: components/libc/posix/signal/posix_signal.c Add comments to the sigqueue function, although it does not have an internal implementation
modified: components/libc/posix/signal/posix_signal.h Added detailed explanation to all members of the rt_signal_value enumeration