From 5e8794b4e101595b9ce93639014412b05824dc16 Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Tue, 25 May 2021 21:20:20 +0200 Subject: [PATCH] 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); | ^~~~~~~ --- app/src/ble.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/ble.c b/app/src/ble.c index b15a079e..3d86d394 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -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));