-
Notifications
You must be signed in to change notification settings - Fork 260
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
undefined behavior: signed integer overflow in minmea_scan() #56
Comments
@invd would you be interested in opening a PR that adds your fuzzing tests to the test build? That seems like a helpful addition. |
@invd, care to share your fuzzing code? I'd love to have that in the repository, so we can test for regressions. |
Also I think the solution here is to check for the overflow of both value and scale, since both can overflow independently:
So basically we have to repeat the overflow logic for both value and scale. I will take care of this soon, just need some sleep first - and I also need to set up fuzzing so I can actually verify this fix was successful. Test cases will also be needed. |
@kosma @cmorganBE #include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include "minmea.h"
// MINMEA_MAX_SENTENCE_LENGTH + 3 + null terminator
#define FUZZER_MAX_BUFFER_LEN MINMEA_MAX_SENTENCE_LENGTH + 3 + 1
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if(size > FUZZER_MAX_BUFFER_LEN - 1) {
return 0;
}
char line[FUZZER_MAX_BUFFER_LEN];
memcpy(line, data, size);
line[size] = 0;
switch (minmea_sentence_id(line, false)) {
case MINMEA_SENTENCE_RMC: {
struct minmea_sentence_rmc frame;
if (minmea_parse_rmc(&frame, line)) {}
} break;
case MINMEA_SENTENCE_GGA: {
struct minmea_sentence_gga frame;
if (minmea_parse_gga(&frame, line)) {}
} break;
case MINMEA_SENTENCE_GSA: {
struct minmea_sentence_gsa frame;
if (minmea_parse_gsa(&frame, line)) {}
} break;
case MINMEA_SENTENCE_GLL: {
struct minmea_sentence_gll frame;
if (minmea_parse_gll(&frame, line)) {}
} break;
case MINMEA_SENTENCE_GST: {
struct minmea_sentence_gst frame;
if (minmea_parse_gst(&frame, line)) {}
} break;
case MINMEA_SENTENCE_GSV: {
struct minmea_sentence_gsv frame;
if (minmea_parse_gsv(&frame, line)) {}
} break;
case MINMEA_SENTENCE_VTG: {
struct minmea_sentence_vtg frame;
if (minmea_parse_vtg(&frame, line)) {}
} break;
case MINMEA_SENTENCE_ZDA: {
struct minmea_sentence_zda frame;
if (minmea_parse_zda(&frame, line)) {}
} break;
default:
// case 'MINMEA_INVALID', 'MINMEA_UNKNOWN',
break;
}
return 0;
} The fuzzer harness is based on the Basic compilation example without sanitizers with everything in the main folder: I've done some basic adjustments to be compatible with your current master revision a0da280 but not tested it further. Feel free to include this code under the WTFPL license. |
At least one signed integer overflow is still present:
|
Thanks so much! This is enough for me to make a proper PR. I'll get this done ASAP. |
Where is the "check.h" file? |
It comes from Check Framework: |
Fuzzing with libFuzzer shows that the following multiplication can lead to undefined behavior:
minmea/minmea.c
Line 186 in 06ad5a1
UndefinedBehavior Sanitizer warning:
Example input:
$y$GGA,,.0651205658
The text was updated successfully, but these errors were encountered: