mruby-esp32 / mruby-esp32-wifi

Wi-Fi library for mruby-esp32.
7 stars 5 forks source link

Potential buffer overflow in char ip_str at mrb_esp32_wifi.c #1

Closed abinoam closed 3 years ago

abinoam commented 3 years ago

While trying to compile https://github.com/mruby-esp32/mruby-esp32 I've got an error from mruby-esp32-wifi.

I think the problem is related to the fact that IPV4 strings may reach a size of 16.'

123.123.123.123 (15 chars plus the 0 terminator character)

I'm opening a PR.

/Users/abinoam/esp/esp-idf/components/esp_netif/include/esp_netif_ip_addr.h:48:15: error: '%d' directive writing between 1 and 3 bytes into a region of size between 1 and 7 [-Werror=format-overflow=]
 #define IPSTR "%d.%d.%d.%d"
               ^~~~~~~~~~~~~
/Users/abinoam/esp/mruby-esp32/components/mruby_component/mruby/build/repos/esp32/mruby-esp32-wifi/src/mrb_esp32_wifi.c:60:25: note: in expansion of macro 'IPSTR'
         sprintf(ip_str, IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip));
                         ^~~~~
/Users/abinoam/esp/esp-idf/components/esp_netif/include/esp_netif_ip_addr.h:48:15: note: directive argument in the range [0, 255]
 #define IPSTR "%d.%d.%d.%d"
               ^~~~~~~~~~~~~
/Users/abinoam/esp/mruby-esp32/components/mruby_component/mruby/build/repos/esp32/mruby-esp32-wifi/src/mrb_esp32_wifi.c:60:25: note: in expansion of macro 'IPSTR'
         sprintf(ip_str, IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip));
                         ^~~~~
/Users/abinoam/esp/mruby-esp32/components/mruby_component/mruby/build/repos/esp32/mruby-esp32-wifi/src/mrb_esp32_wifi.c:60:9: note: 'sprintf' output between 8 and 16 bytes into a destination of size 13
         sprintf(ip_str, IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip));

PS: By the way, I couldn't compile mruby-esp32 against mruby's master branch.

abinoam commented 3 years ago

Dear @pandax381

By the way, I'm trying to compile mruby-esp32 examples against mruby master branch. I have opened 2 issues (with 2 PRs) at mruby today. https://github.com/mruby/mruby/issues/5175 https://github.com/mruby/mruby/issues/5177

abinoam commented 3 years ago

Closed by 8cc946e and 81df0fe