laamaa / m8c

Cross-platform M8 tracker headless client
Other
382 stars 81 forks source link

Fix serial read error checking bug #40

Closed daniel214 closed 2 years ago

daniel214 commented 2 years ago

size_t is unsigned, so sp_blocking_read() errors are cast to a non-negative value and skip the check on line 111.

This also causes bytes_read to appear to be a very large number (much bigger than serial_read_size) which sends lots of junk to the SLIP call and eventually causes a segfault.

This can be duplicated for test by starting the M8 without an SD card inserted or by unplugging the M8 from USB after it has launched. Old behavior: Floods of SLIP error 1 messages, then a segfault. New behavior:

CRITICAL: Error -2 reading serial. 
2022-02-26 23:37:08.338 m8c[15120:28714504] INFO: Shutting down
2022-02-26 23:37:08.360 m8c[15120:28714504] INFO: Disconnecting M8
2022-02-26 23:37:08.360 m8c[15120:28714504] ERROR: Error sending disconnect, code -2

(program terminates)

laamaa commented 2 years ago

Thank you! Merged.