Skip to content

Commit 13ee3f8

Browse files
zhuanglinxxiaoxiang781216
authored andcommitted
sched/clock Add special handling for TCB null pointer cases
Adding a judgment in the code that null return values are not referenced for dereference Signed-off-by: zhuanglin <[email protected]>
1 parent 2db471f commit 13ee3f8

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

sched/clock/clock_gettime.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
153153
tcb = nxsched_get_tcb(pid);
154154
}
155155

156-
up_perf_convert(tcb->run_time, tp);
156+
if (tcb != NULL)
157+
{
158+
up_perf_convert(tcb->run_time, tp);
159+
}
160+
else
161+
{
162+
ret = -EFAULT;
163+
}
157164
}
158165
else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
159166
{
@@ -174,18 +181,28 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
174181
tcb = nxsched_get_tcb(pid);
175182
}
176183

177-
group = tcb->group;
178-
runtime = 0;
184+
if (tcb != NULL)
185+
{
186+
group = tcb->group;
187+
runtime = 0;
188+
189+
flags = enter_critical_section();
190+
for (i = group->tg_nmembers - 1; i >= 0; i--)
191+
{
192+
tcb = nxsched_get_tcb(group->tg_members[i]);
193+
if (tcb != NULL)
194+
{
195+
runtime += tcb->run_time;
196+
}
197+
}
179198

180-
flags = enter_critical_section();
181-
for (i = group->tg_nmembers - 1; i >= 0; i--)
199+
leave_critical_section(flags);
200+
up_perf_convert(runtime, tp);
201+
}
202+
else
182203
{
183-
tcb = nxsched_get_tcb(group->tg_members[i]);
184-
runtime += tcb->run_time;
204+
ret = -EFAULT;
185205
}
186-
187-
leave_critical_section(flags);
188-
up_perf_convert(runtime, tp);
189206
}
190207
#endif
191208
else

0 commit comments

Comments
 (0)