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

Parsing will cause NULL pointer exceptions when parsing malformed sentences. #154

Open
jpuderer opened this issue Jan 28, 2024 · 8 comments

Comments

@jpuderer
Copy link

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.

@jpuderer
Copy link
Author

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

@jpuderer
Copy link
Author

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!).

@jpuderer
Copy link
Author

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.

@sellensr
Copy link
Contributor

sellensr commented Jan 29, 2024 via email

@svdrummer
Copy link

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.

@sellensr
Copy link
Contributor

sellensr commented Jan 29, 2024 via email

@jpuderer
Copy link
Author

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

@jpuderer
Copy link
Author

Hello?

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

No branches or pull requests

3 participants