apache / mynewt-nimble

Apache mynewt
https://mynewt.apache.org/
Apache License 2.0
665 stars 385 forks source link

controller/ble_ll_sync.c: acad_len potentially uninitialised #1739

Closed KKopyscinski closed 3 months ago

KKopyscinski commented 3 months ago

acad_len in ble_ll_sync_rx_pkt_in is filled in ble_ll_sync_parse_ext_hdr and later accessed in ble_ll_sync_check_acad. There is a possibility that extended advertising header is missing data containing acad, and it will not get filled, leaving it uninitialised.

This fixes compilation warning:

Error: In function 'ble_ll_sync_check_acad',
    inlined from 'ble_ll_sync_rx_pkt_in' at repos/apache-mynewt-nimble/nimble/controller/src/ble_ll_sync.c:1207:18:
repos/apache-mynewt-nimble/nimble/controller/src/ble_ll_sync.c:1064:21: error: 'acad_len' may be used uninitialized [-Werror=maybe-uninitialized]
 1064 |     while (acad_len > 2) {
      |            ~~~~~~~~~^~~
repos/apache-mynewt-nimble/nimble/controller/src/ble_ll_sync.c: In function 'ble_ll_sync_rx_pkt_in':
repos/apache-mynewt-nimble/nimble/controller/src/ble_ll_sync.c:1139:13: note: 'acad_len' was declared here
 1139 |     uint8_t acad_len;
      |             ^~~~~~~~
cc1: all warnings being treated as errors