fix(core): Fix overflow in setting_name sprintf

With newlib_libc enabled, a warning was printed for this sprintf.
The settings_name may expand to 17 characters instead of the available
15.

Fixes #808.

Full warning:

[49/272] Building C object CMakeFiles/app.dir/src/ble.c.obj
In file included from /home/okke/.local/zephyr-sdk-0.11.2/arm-zephyr-eabi/arm-zephyr-eabi/sys-include/stdio.h:800,
                 from ../../src/ble.c:12:
../../src/ble.c: In function 'set_profile_address':
../../src/ble.c:118:27: warning: '%d' directive writing between 1 and 3 bytes into a region of size 2 [-Wformat-overflow=]
  118 |     sprintf(setting_name, "ble/profiles/%d", index);
      |                           ^~~~~~~~~~~~~~~~~
../../src/ble.c:118:41: note: format string is defined here
  118 |     sprintf(setting_name, "ble/profiles/%d", index);
      |                                         ^~
In file included from /home/okke/.local/zephyr-sdk-0.11.2/arm-zephyr-eabi/arm-zephyr-eabi/sys-include/stdio.h:800,
                 from ../../src/ble.c:12:
../../src/ble.c:118:27: note: directive argument in the range [0, 255]
  118 |     sprintf(setting_name, "ble/profiles/%d", index);
      |                           ^~~~~~~~~~~~~~~~~
../../src/ble.c:118:5: note: '__builtin___sprintf_chk' output between 15 and 17 bytes into a destination of size 15
  118 |     sprintf(setting_name, "ble/profiles/%d", index);
      |     ^~~~~~~
This commit is contained in:
Okke Formsma 2021-05-25 21:20:20 +02:00
parent 18ef73e949
commit 5e8794b4e1

View file

@ -109,7 +109,7 @@ bool zmk_ble_active_profile_is_open() {
}
void set_profile_address(uint8_t index, const bt_addr_le_t *addr) {
char setting_name[15];
char setting_name[17];
char addr_str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));