-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Bluetooth: drivers: userchan: Fix gcc 13 overflow warning #76885
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
Conversation
drivers/bluetooth/hci/userchan.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't ssize_t be a better type, considering the usage (e.g. doing operations together with other ssize_t variables like len)?
That said, there's int32_t decoded_len later in the function which might be better updated to ssize_t too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed :)
(decoded_len is already the return type of hci_packet_complete() so it should not be a problem even in theory :) )
gcc 13 produces a build warning (see below), as it seems to
believe the number of read bytes may overflow the frame_size
type.
Let's increase the frame_size bitwidth to avoid this.
(Any 32bit type, signed or unsigned, avoids this warning)
The build warning:
```
In file included from /usr/include/features.h:502,
from bits/libc-header-start.h:33,
from /usr/include/stdint.h:26,
from include/stdint.h:9,
from zephyr/include/zephyr/types.h:11,
from zephyr/include/zephyr/kernel_includes.h:21,
from zephyr/include/zephyr/kernel.h:17,
from zephyr/drivers/bluetooth/hci/userchan.c:9:
In function ‘read’,
inlined from ‘rx_thread’ at drivers/bluetooth/hci/userchan.c:201:9:
/usr/include/i386-linux-gnu/bits/unistd.h:28:10: warning: ‘__read_alias’
specified size between 4294902273 and 4294967295 exceeds maximum object
size 2147483647
[-Wstringop-overflow=]
28 | return __glibc_fortify (read, __nbytes, sizeof (char),
| ^~~~~~~~~~~~~~~
drivers/bluetooth/hci/userchan.c: In function ‘rx_thread’:
drivers/bluetooth/hci/userchan.c:187:32: note: destination object allocated
here
187 | static uint8_t frame[512];
| ^~~~~
/usr/include/i386-linux-gnu/bits/unistd-decl.h:29:16: note: in a call to
function
‘__read_alias’ declared with attribute ‘access (write_only, 2, 3)’
29 | extern ssize_t __REDIRECT_FORTIFY (__read_alias, (int __fd, void
| ^~~~~~~~~~~~~~~~~~
```
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
gcc 13 produces a build warning (see below), as it seems to believe the number of read bytes may overflow the frame_size type.
Let's increase the frame_size bitwidth to avoid this. (Any 32bit type, signed or unsigned, avoids this warning)
The build warning:
Fixes #76912