Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverity CID :215243] Unintentional integer overflow in drivers/timer/stm32_lptim_timer.c #29697

Closed
zephyrbot opened this issue Nov 2, 2020 · 1 comment · Fixed by #31142
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug

Comments

@zephyrbot
Copy link
Collaborator

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/c9a2a5e7fb0194bfb168f5aa1a0a83c73f62acb3/drivers/timer/stm32_lptim_timer.c#L313

Category: Integer handling issues
Function: z_timer_cycle_get_32
Component: Drivers
CID: 215243

Details:

307             lp_time += LL_LPTIM_GetAutoReload(LPTIM1) + 1;
308         }
309    
310         lp_time += accumulated_lptim_cnt;
311    
312         /* convert lptim count in a nb of hw cycles with precision */
>>>     CID 215243:  Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
>>>     Potentially overflowing expression "lp_time * (sys_clock_hw_cycles_per_sec() / 32768)" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).
313         uint64_t ret = lp_time * (sys_clock_hw_cycles_per_sec() / LPTIM_CLOCK);
314    
315         k_spin_unlock(&lock, key);
316    
317         /* convert in hw cycles (keeping 32bit value) */
318         return (uint32_t)(ret);

Please fix or provide comments in coverity using the link:

https://scan9.coverity.com/reports.htm#v32951/p12996.

Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the CODEOWNERS file.

@zephyrbot zephyrbot added bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug labels Nov 2, 2020
@github-actions
Copy link

github-actions bot commented Jan 2, 2021

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants