adafruit/Adafruit_GPS

Parsing will cause NULL pointer exceptions when parsing malformed sentences.

jpuderer opened this issue · 8 comments

p = strchr(p, ',') + 1; // Skip to char after the next comma, then check.

These strchr expressions are everywhere in the code, and will result in a null pointer exception if ever fed a malformed sentence that's missing a comma somewhere. If that's a limitation fine, but it makes the library pretty intolerant to line noise.

Correction, not quite a NULL pointer exception, but close enough. p will actually point to 0x00000001 which is also an invalid address.

It seems that this is somehow happening despite the passing the checksum. I'll have to dig into it. It's hard to catch, since it seems to happen only after running for a while. Adding print statements seems to make it occur much less frequently (a Heisenbug!).

As it turns out, I was getting a lot of invalid NMEA sentences that were getting silently discarded. However, an NMEA checksum is only a single byte, so eventually I win the lottery (1/256 chance) and try to parse an invalid NMEA sentence with a valid checksum.

This happens easily enough if you aren't calling the libraries read() function frequently enough, and miss some characters. This is a known issue.

You can't always call read() frequently enough either. If you are producing a lot of serial output for example, or other IO, it is easy to conceive of a situation in which you don't call read() before a character gets dropped. The correct solution to this of course, is to service the UART in a ISR, but that isn't the kind of thing that most people will know how to do (this is an Arduino library that attracts mostly learners and tinkerers...)

Considering all this, we should probably make the calls to strchr() a little more robust to detect when something is amiss. 1/256 is just too high a chance to accidentally pass the checksum with an invalid sentence that will then fatally crash the board.

As the UNO is sooooo old and has been replaced with so many, much more powerful options, is it worth someone spending time writing a library for such an old device.

Can someone look at my pull request? It works, is tested, and uses less memory.

Hello?