Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent null pointer dereference in setup() if radio is not available. #1166

Merged
merged 2 commits into from
Jan 28, 2022

Conversation

rnauber
Copy link

@rnauber rnauber commented Jan 28, 2022

Hi,
if your device's radio is not recognized, a nasty null pointer dereference crashes your device. This patch fixes that.

Best,
Richard


--- Miniterm on /dev/ttyUSB0  921600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
??:??:?? 2 ERROR: No UBLOX GPS found
??:??:?? 2 Hoping that NMEA might work
??:??:?? 2 WANT GPS=1
??:??:?? 2 GxGSA NOT available
??:??:?? 2 External Notification Plugin Disabled
??:??:?? 2 NOTE! Recording critical error 6 at src/main.cpp:21f
??:??:?? 2 Starting meshradio init...
??:??:?? 2 (bw=125, sf=12, cr=4/8) packet symLen=32 ms, payloadSize=16, time 2269 ms
??:??:?? 2 Set radio: name=LongSlow, config=3, ch=0, power=0
??:??:?? 2 Radio myRegion->freq: 903.080017
??:??:?? 2 Radio myRegion->spacing: 2.160000
??:??:?? 2 Radio myRegion->numChannels: 13
??:??:?? 2 Radio channel_num: 0
??:??:?? 2 Radio frequency: 903.080017
??:??:?? 2 Short packet time: 2269 msec
??:??:?? 2 Set radio: final power level=17
??:??:?? 2 RF95 init result -2
??:??:?? 2 Current limit set to 100.000000
??:??:?? 2 Current limit set result -16
??:??:?? 2 Warning: Failed to find RF95 radio
??:??:?? 2 Starting meshradio init...
??:??:?? 2 (bw=125, sf=12, cr=4/8) packet symLen=32 ms, payloadSize=16, time 2269 ms
??:??:?? 2 Set radio: name=LongSlow, config=3, ch=0, power=0
??:??:?? 2 Radio myRegion->freq: 903.080017
??:??:?? 2 Radio myRegion->spacing: 2.160000
??:??:?? 2 Radio myRegion->numChannels: 13
??:??:?? 2 Radio channel_num: 0
??:??:?? 2 Radio frequency: 903.080017
??:??:?? 2 Short packet time: 2269 msec
??:??:?? 2 Set radio: final power level=22
??:??:?? 5 SX126x init result -2
??:??:?? 5 Current limit set to 140.000000
??:??:?? 5 Current limit set result -707
??:??:?? 5 Warning: Failed to find SX1262 radio
??:??:?? 5 WiFi ... Forced AP Mode
??:??:?? 5 Waiting for SSL Cert to be generated.
??:??:?? 5 Existing SSL Certificate found!
??:??:?? 5 Retrieved Private Key: 1193 Bytes
??:??:?? 5 Retrieved Certificate: 780 Bytes
??:??:?? 5 SSL Cert Ready!
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
??:??:?? 5 ************ [WiFi-event] event: 0 ************
??:??:?? 5 WiFi interface ready
??:??:?? 5 Starting (Forced) WIFI AP: ssid=meshtasticAdmin, ok=1
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 14 - AP_START
??:??:?? 5 ************ [WiFi-event] event: 14 ************
??:??:?? 5 WiFi access point started
??:??:?? 5 ... Starting network services
??:??:?? 5 mDNS responder started
??:??:?? 5 mDNS Host: Meshtastic.local
??:??:?? 5 MY IP AP ADDRESS: 192.168.42.1
??:??:?? 5 Starting NTP time client
??:??:?? 5 Initializing Web Server ...
??:??:?? 5 Starting Secure Web Server...
??:??:?? 5 Starting Insecure Web Server...
??:??:?? 5 Web Servers Ready! :-) 
??:??:?? 5 API server listening on TCP port 4403
??:??:?? 5 NOTE! Recording critical error 3 at src/main.cpp:294
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400e0f8c  PS      : 0x00060430  A0      : 0x800dda89  A1      : 0x3ffd34b0  
A2      : 0x00000000  A3      : 0x000000ed  A4      : 0x00000001  A5      : 0x3ffc9de0  
A6      : 0x447a0000  A7      : 0x3ffbb688  A8      : 0x00060023  A9      : 0x3ffbac7c  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x80090ca8  A13     : 0x3ffd33e0  
A14     : 0x00000000  A15     : 0x3ffd15c0  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000048  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffc  

ELF file SHA256: 0000000000000000

Backtrace: 0x400e0f8c:0x3ffd34b0 0x400dda86:0x3ffd3500 0x401213c2:0x3ffd3530
  #0  0x400e0f8c:0x3ffd34b0 in RadioInterface::getPacketTime(unsigned int) at src/mesh/RadioInterface.h:205
  #1  0x400dda86:0x3ffd3500 in setup() at src/main.cpp:667
  #2  0x401213c2:0x3ffd3530 in loopTask(void*) at /home/olg/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:14

Rebooting...

Copy link
Member

@mc-hamster mc-hamster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent! Thank you! Will merge as soon as the CI completes.

@mc-hamster mc-hamster merged commit 5288f18 into meshtastic:master Jan 28, 2022
@rnauber rnauber deleted the fix_nullptrderef branch January 28, 2022 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants