RTEMS | time_t assigned to uint32_t results in value truncation (#5737)
Sharvin Neve (@Sharvin)
gitlab at rtems.org
Tue Sep 8 18:25:12 UTC 2026
Sharvin Neve commented: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5737#note_158885
Hi Joel (@joel),
I investigated the Coverity defects reported in this issue and implemented a patch addressing all three subsystems:
1. **`cpukit/libmisc/cpuuse/cpuusagetop.c` (CID 1512539)**:
- Updated `print_time()` to decompose seconds as `uint64_t` instead of `uint32_t`, avoiding 32-bit truncation when uptime or execution time exceeds $2^{32}-1$ seconds.
- Clamped negative timestamps to 0 and corrected unit rollover boundaries to `>=` so exact boundary values (60s, 60m, 24h) roll over cleanly to the next unit. Preserved 32-bit divisions for sub-day units.
2. **CBS Scheduler (CID 1512546)**:
- `the_thread->CPU_budget.available` is `uint32_t`, while `Scheduler_CBS_Parameters.budget` is `time_t`.
- Added validation in both `_Scheduler_CBS_Create_server()` and `_Scheduler_CBS_Set_parameters()` rejecting any budget exceeding `UINT32_MAX` with `SCHEDULER_CBS_ERROR_INVALID_PARAMETER` (using `((uint64_t) params->budget) > UINT32_MAX` to avoid `-Wtype-limits` warnings on 32-bit `time_t` architectures under `-Werror`).
- Added explicit `(uint32_t)` cast in `_Scheduler_CBS_Release_job()` upon budget replenishment.
3. **`bsps/shared/dev/getentropy/getentropy-cpucounter.c` (CID 1512551)**:
- Converted `bt.sec` to `uint64_t` via `(uint64_t)(uintptr_t) bt.sec` before bit-shifting `sec >> 32`, eliminating undefined behavior when shifting signed `time_t` on 32-bit systems while preventing sign-extension artifacts.
The patch is committed and formatted with `Closes #5737.`. Would you prefer a GitLab Merge Request or a patch submitted to `devel at rtems.org`?
--
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5737#note_158885
You're receiving this email because of your account on gitlab.rtems.org. Unsubscribe from this thread: https://gitlab.rtems.org/-/sent_notifications/5-7o62feos5am30ozoro5w5ek6z-1d/unsubscribe | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | Help: https://gitlab.rtems.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20260908/a186635e/attachment-0001.htm>
More information about the bugs
mailing list