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 :207984] Sizeof not portable in drivers/counter/counter_handlers.c #22431

Closed
zephyrbot opened this issue Feb 3, 2020 · 4 comments · Fixed by #23698
Closed

[Coverity CID :207984] Sizeof not portable in drivers/counter/counter_handlers.c #22431

zephyrbot opened this issue Feb 3, 2020 · 4 comments · Fixed by #23698
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/a3e89e84a801d9bc048b0ee2177f0fb11d1a925a/drivers/counter/counter_handlers.c#L71

Category: Code maintainability issues
Function: z_vrfy_counter_get_value
Component: Drivers
CID: 207984

Details:

65     #include <syscalls/counter_ticks_to_us_mrsh.c>
66    
67     static inline int z_vrfy_counter_get_value(struct device *dev,
68                            u32_t *ticks)
69     {
70         Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, get_value));
>>>     CID 207984:  Code maintainability issues  (SIZEOF_MISMATCH)
>>>     Passing argument "ticks" of type "u32_t *" and argument "4U /* sizeof (ticks) */" to function "arch_buffer_validate" is suspicious. In this case, "sizeof (u32_t *)" is equal to "sizeof (u32_t)", but this is not a portable assumption.
71         Z_OOPS(Z_SYSCALL_MEMORY_WRITE(ticks, sizeof(ticks)));
72         return z_impl_counter_get_value((struct device *)dev, ticks);
73     }
74     #include <syscalls/counter_get_value_mrsh.c>
75    
76     static inline int z_vrfy_counter_set_channel_alarm(struct device *dev,

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 Feb 3, 2020
@henrikbrixandersen
Copy link
Member

I am not sure why this was flagged by coverity? Can somebody please explain?

@nordic-krch
Copy link
Contributor

also have no idea.

@ceolin
Copy link
Member

ceolin commented Mar 23, 2020

sizeof(ticks) will return the size of a pointer that can be different from the size of u32_t. In 64 bits architecture pointers are 8 bytes long and u32_t is 4 bytes.

ceolin added a commit to ceolin/zephyr that referenced this issue Mar 23, 2020
z_vrfy_counter_get_value should check the size of memory pointed to
ticks and not the size of the pointer.

Fixes: zephyrproject-rtos#22431
Coverity CID :207984

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
@ceolin
Copy link
Member

ceolin commented Mar 23, 2020

Fixed by: #23698

ioannisg pushed a commit that referenced this issue Mar 25, 2020
z_vrfy_counter_get_value should check the size of memory pointed to
ticks and not the size of the pointer.

Fixes: #22431
Coverity CID :207984

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
hakehuang pushed a commit to hakehuang/zephyr that referenced this issue Apr 30, 2020
z_vrfy_counter_get_value should check the size of memory pointed to
ticks and not the size of the pointer.

Fixes: zephyrproject-rtos#22431
Coverity CID :207984

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
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.

4 participants