More afl fixes.

This commit is contained in:
Ian Gulliver
2016-02-26 23:36:05 -08:00
parent c315de6354
commit 675fb51282
3 changed files with 14 additions and 2 deletions

View File

@@ -90,8 +90,10 @@ static bool json_parse_header(json_t *in, struct packet *packet, struct json_par
} }
if (mlat_timestamp_mhz > UINT16_MAX || if (mlat_timestamp_mhz > UINT16_MAX ||
mlat_timestamp_max < 0 || mlat_timestamp_mhz <= 0 ||
rssi_max > UINT32_MAX) { mlat_timestamp_max <= 0 ||
rssi_max > UINT32_MAX ||
rssi_max <= 0) {
return false; return false;
} }

View File

@@ -13,6 +13,7 @@ char *packet_type_names[] = {
}; };
static uint64_t packet_mlat_timestamp_scale_mhz_in(uint64_t timestamp, uint32_t mhz) { static uint64_t packet_mlat_timestamp_scale_mhz_in(uint64_t timestamp, uint32_t mhz) {
assert(mhz > 0);
return timestamp * (PACKET_MLAT_MHZ / mhz); return timestamp * (PACKET_MLAT_MHZ / mhz);
} }
@@ -27,10 +28,12 @@ static uint64_t packet_mlat_timestamp_scale_width_in(uint64_t timestamp, uint64_
} }
static uint64_t packet_mlat_timestamp_scale_mhz_out(uint64_t timestamp, uint64_t mhz) { static uint64_t packet_mlat_timestamp_scale_mhz_out(uint64_t timestamp, uint64_t mhz) {
assert(mhz > 0);
return timestamp / (PACKET_MLAT_MHZ / mhz); return timestamp / (PACKET_MLAT_MHZ / mhz);
} }
static uint64_t packet_mlat_timestamp_scale_width_out(uint64_t timestamp, uint64_t max) { static uint64_t packet_mlat_timestamp_scale_width_out(uint64_t timestamp, uint64_t max) {
assert(max > 0);
return timestamp % max; return timestamp % max;
} }
@@ -43,10 +46,12 @@ uint64_t packet_mlat_timestamp_scale_out(uint64_t timestamp, uint64_t max, uint1
} }
uint32_t packet_rssi_scale_in(uint32_t value, uint32_t max) { uint32_t packet_rssi_scale_in(uint32_t value, uint32_t max) {
assert(max > 0);
return value * (PACKET_RSSI_MAX / max); return value * (PACKET_RSSI_MAX / max);
} }
uint32_t packet_rssi_scale_out(uint32_t value, uint32_t max) { uint32_t packet_rssi_scale_out(uint32_t value, uint32_t max) {
assert(max > 0);
return value / (PACKET_RSSI_MAX / max); return value / (PACKET_RSSI_MAX / max);
} }

View File

@@ -91,11 +91,16 @@ static bool proto_parse_header(AdsbHeader *header, struct packet *packet, struct
return false; return false;
} }
state->have_header = true;
fprintf(stderr, "R %s: Connected to server ID: %s\n", packet->source_id, header->server_id); fprintf(stderr, "R %s: Connected to server ID: %s\n", packet->source_id, header->server_id);
return true; return true;
} }
static bool proto_parse_packet(AdsbPacket *in, struct packet *packet, struct proto_parser_state *state, size_t len) { static bool proto_parse_packet(AdsbPacket *in, struct packet *packet, struct proto_parser_state *state, size_t len) {
if (!state->have_header) {
return false;
}
if (in->payload.len != len) { if (in->payload.len != len) {
return false; return false;
} }