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

Fix UBSAN bugs #2845

Merged
merged 9 commits into from
Jun 29, 2024
Merged

Fix UBSAN bugs #2845

merged 9 commits into from
Jun 29, 2024

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Jun 28, 2024

This PR fixes some potential/actual bugs identified by the undefined behaviour sanitizer.
Several of these became apparent with -Wextra, mainly through 'unused parameter' warnings, of which there are many.

String::replace: Passing nullptr to memcpy is undefined behaviour

axtls sha1: Undefined behaviour

axtls-8266/crypto/sha1.c:124:42: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior axtls-8266/crypto/sha1.c:124:42

Because: implicit conversion of uint8_t to int

Don't force queueCallback with no parameter

Sanitizer reports undefined behaviour passing parameter to function which doesn't expect one.
Works fine in practice but safer to add a lamba for dealing with it.

Stream::parseFloat() not handling timeout

String(unsigned char, ...) ignoring width, pad parameters

char could be signed, check for > 127 would never succeed

HostTests datetime check should use parameter

Fix unimplemented host RtcClass::setRtcNanoseconds()

Potential array bounds violation in esp-open-lwip dhcp.c

Check for index in range should be first.

lwip/core/dhcp.c: In function 'dhcp_recv':
lwip/core/dhcp.c:133:69: warning: array subscript 10 is above array bounds of 'u8_t[10]' {aka 'unsigned char[10]'} [-Warray-bounds]
  133 | #define dhcp_option_given(dhcp, idx)          (dhcp_rx_options_given[idx] != 0)
      |                                                ~~~~~~~~~~~~~~~~~~~~~^~~~~
lwip/core/dhcp.c:592:9: note: in expansion of macro 'dhcp_option_given'
  592 |   while(dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n) && (n < DNS_MAX_SERVERS)) {
      |         ^~~~~~~~~~~~~~~~~
lwip/core/dhcp.c:131:7: note: while referencing 'dhcp_rx_options_given'
  131 | u8_t  dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
      |       ^~~~~~~~~~~~~~~~~~~~~

mikee47 added 8 commits June 28, 2024 15:51
axtls-8266/crypto/sha1.c:124:42: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior axtls-8266/crypto/sha1.c:124:42

Because: implicit conversion of uint8_t to int
Sanitizer reports undefined behaviour passing parameter to function which doesn't expect one.
Works fine in practice but safer to add a lamba for dealing with it.
@slaff slaff added this to the 5.2.0 milestone Jun 28, 2024
```
lwip/core/dhcp.c: In function 'dhcp_recv':
lwip/core/dhcp.c:133:69: warning: array subscript 10 is above array bounds of 'u8_t[10]' {aka 'unsigned char[10]'} [-Warray-bounds]
  133 | #define dhcp_option_given(dhcp, idx)          (dhcp_rx_options_given[idx] != 0)
      |                                                ~~~~~~~~~~~~~~~~~~~~~^~~~~
lwip/core/dhcp.c:592:9: note: in expansion of macro 'dhcp_option_given'
  592 |   while(dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n) && (n < DNS_MAX_SERVERS)) {
      |         ^~~~~~~~~~~~~~~~~
lwip/core/dhcp.c:131:7: note: while referencing 'dhcp_rx_options_given'
  131 | u8_t  dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
      |       ^~~~~~~~~~~~~~~~~~~~~
```
@slaff slaff merged commit 3db6495 into SmingHub:develop Jun 29, 2024
48 checks passed
@mikee47 mikee47 deleted the fix/potential-bugs branch June 29, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants