arduino / ArduinoCore-mbed

347 stars 202 forks source link

missing null pointer checks #889

Closed ddmesh closed 4 months ago

ddmesh commented 5 months ago

https://github.com/arduino/ArduinoCore-mbed/blob/dd5abb6171063b2777620b9339510c63b915ce72/libraries/Ethernet/src/Ethernet.cpp#L6

Per default an object is created via arduino::EthernetClass Ethernet;. In this case the eth_if member got initialized (which is a pointer).

But when user creates his own object and passes a null pointer for EthernetInterface() arduino::EthernetClass Ethernet(nullptr); Several calls to other public functions, will directly call/access the null pointer.

https://github.com/arduino/ArduinoCore-mbed/blob/dd5abb6171063b2777620b9339510c63b915ce72/libraries/Ethernet/src/Ethernet.cpp#L17 https://github.com/arduino/ArduinoCore-mbed/blob/dd5abb6171063b2777620b9339510c63b915ce72/libraries/Ethernet/src/Ethernet.cpp#L56 https://github.com/arduino/ArduinoCore-mbed/blob/dd5abb6171063b2777620b9339510c63b915ce72/libraries/Ethernet/src/Ethernet.cpp#L71 https://github.com/arduino/ArduinoCore-mbed/blob/dd5abb6171063b2777620b9339510c63b915ce72/libraries/Ethernet/src/Ethernet.cpp#L80

manchoz commented 5 months ago

Hey, @ddmesh, would you mind adding the null-pointer checks where needed and submitting a PR?

Thanks!