Skip to content

Commit

Permalink
nimble/host: Fix not catching conversion error in hex2bin
Browse files Browse the repository at this point in the history
hex2val returns BLE_HS_EINVAL on error which is positive value.
This could result in UUID conversion errors as hex2bin is used
by ble_uuid_from_str.

This was also causing build error with GCC 9:

repos/apache-mynewt-nimble/nimble/host/src/ble_uuid.c:76:28: error:
     'tmp_val' may be used uninitialized in this function
     [-Werror=maybe-uninitialized]
   76 |         bin[len] = tmp_val << 4;
      |                    ~~~~~~~~^~~~
cc1: all warnings being treated as errors
  • Loading branch information
sjanc committed Oct 4, 2023
1 parent 1306a78 commit 20241c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nimble/host/src/ble_uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ hex2bin(const char *hex, uint8_t *bin, size_t bin_len)

while (*hex && len < bin_len) {
rc = hex2val(*hex++, &tmp_val);
if (rc < 0) {
if (rc != 0) {
return 0;
}

Expand All @@ -81,7 +81,7 @@ hex2bin(const char *hex, uint8_t *bin, size_t bin_len)
}

rc = hex2val(*hex++, &tmp_val);
if (rc < 0) {
if (rc != 0) {
return 0;
}
bin[len++] |= tmp_val;
Expand Down

0 comments on commit 20241c2

Please sign in to comment.