Commit 195258d
authored
Fix buffer overflow in set_pin_code() (#802)
set_pin_code() copies the caller-supplied pin string into pin_code
with strcpy and no length check, but pin_code is a fixed
esp_bt_pin_code_t, i.e. uint8_t[16]. Any pin of 16 characters or more
(the Bluetooth spec allows PINs up to 16 digits, and the function
takes an arbitrary const char* so nothing stops a caller from passing
something longer) overwrites whatever member happens to follow
pin_code in memory - pin_code_len right now, but really anything else
depending on how the class layout changes over time.
This bounds the copy to the size of the buffer and keeps pin_code
NUL-terminated. pin_code_len is now set from the actual (possibly
truncated) length instead of the untruncated strlen(), so it stays
consistent with what actually ended up in pin_code, and the two
places that read pin_code/pin_code_len afterwards (the initial
esp_bt_gap_set_pin call and the pin_req callback's pin_reply) keep
working correctly.1 parent a39ecc1 commit 195258d
1 file changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
93 | 100 | | |
94 | 101 | | |
95 | 102 | | |
| |||
0 commit comments