未验证 提交 ab7ab19b 编写于 作者: G geniusgogo 提交者: GitHub

fixed ctime timer_delete timerid parameter check. (#6977)

* fixed ctime timer_delete timerid parameter check.
上级 cdd2755b
...@@ -967,9 +967,15 @@ void timer_id_unlock() ...@@ -967,9 +967,15 @@ void timer_id_unlock()
rt_hw_spin_unlock(&_timer_id_lock); rt_hw_spin_unlock(&_timer_id_lock);
} }
struct timer_obj *timer_id_get(int timerid) struct timer_obj *timer_id_get(rt_ubase_t timerid)
{ {
struct timer_obj *timer; struct timer_obj *timer;
if (timerid < 0 || timerid >= TIMER_ID_MAX)
{
return NULL;
}
timer_id_lock(); timer_id_lock();
if (_g_timerid[timerid] == NULL) if (_g_timerid[timerid] == NULL)
{ {
...@@ -1071,16 +1077,26 @@ RTM_EXPORT(timer_create); ...@@ -1071,16 +1077,26 @@ RTM_EXPORT(timer_create);
int timer_delete(timer_t timerid) int timer_delete(timer_t timerid)
{ {
struct timer_obj *timer; struct timer_obj *timer;
rt_ubase_t ktimerid;
ktimerid = (rt_ubase_t)timerid;
if (ktimerid < 0 || ktimerid >= TIMER_ID_MAX)
{
rt_set_errno(EINVAL);
return -1;
}
timer_id_lock(); timer_id_lock();
if (_g_timerid[(rt_ubase_t)timerid] == NULL) if (_g_timerid[ktimerid] == NULL)
{ {
timer_id_unlock(); timer_id_unlock();
rt_set_errno(EINVAL); rt_set_errno(EINVAL);
LOG_E("can not find timer!"); LOG_E("can not find timer!");
return -1; return -1;
} }
timer = _g_timerid[(rt_ubase_t)timerid]; timer = _g_timerid[ktimerid];
timer_id_put((rt_ubase_t)timerid); timer_id_put(ktimerid);
timer_id_unlock(); timer_id_unlock();
if (timer == RT_NULL) if (timer == RT_NULL)
{ {
...@@ -1132,9 +1148,11 @@ int timer_getoverrun(timer_t timerid) ...@@ -1132,9 +1148,11 @@ int timer_getoverrun(timer_t timerid)
*/ */
int timer_gettime(timer_t timerid, struct itimerspec *its) int timer_gettime(timer_t timerid, struct itimerspec *its)
{ {
struct timer_obj *timer = timer_id_get((rt_ubase_t)timerid); struct timer_obj *timer;
rt_uint32_t seconds, nanoseconds; rt_uint32_t seconds, nanoseconds;
timer = timer_id_get((rt_ubase_t)timerid);
if (timer == NULL) if (timer == NULL)
{ {
rt_set_errno(EINVAL); rt_set_errno(EINVAL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册