Skip to content

fix: fixes infinit loop in checksum calculation due to integer overflow#1

Open
CheerThe2nd wants to merge 1 commit into
pcdangio:mainfrom
CheerThe2nd:main
Open

fix: fixes infinit loop in checksum calculation due to integer overflow#1
CheerThe2nd wants to merge 1 commit into
pcdangio:mainfrom
CheerThe2nd:main

Conversation

@CheerThe2nd
Copy link
Copy Markdown

I noticed that when using nmea::sentence::validate(nmeaBlock); and the passed nmeaBlock contains 3 or more nmea sentences, the checksum generation inside of nmea::sentence::validate halts for ever. After investigating I noticted that, inside of std::string sentence::checksum, a for loop is started which uses a 8 bit unsigned integer as index. And the end condition, for previously named for loop, is bigger than 255. So the for loop can never end since the 8 bit index will keep overflowing back to 0. To Fix this a higher bit value should be used as index.

This snippet will reproduce the issue if used on the old version:

 const std::string testNmea = "$GPGGA,172814.0,3723.46587704,N,12202.26957864,W,2,6,1.2,18.893,M,-25.669,M,2.0,0031*4F\r\n";
    for (int i = 0; i < 15; ++i)
    {
        printf("Now testing block size %d \n", i);
        std::string nmeaBlock;
        for(int k = 0; k < i; ++k)
            nmeaBlock += testNmea;

        printf("Current block %s\n", nmeaBlock.c_str());
        nmea::sentence::validate(nmeaBlock);
    }

    return 0;

@CheerThe2nd
Copy link
Copy Markdown
Author

In hindsight you could also just use the same type, for the index, which is used to store the end condition

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.

1 participant