Fix server_id overflow due to utf8 blowup in json.
This commit is contained in:
@@ -99,6 +99,10 @@ static bool json_parse_header(json_t *in, struct packet *packet, struct json_par
|
||||
state->mlat_timestamp_max = (uint64_t) mlat_timestamp_max;
|
||||
state->rssi_max = (uint32_t) rssi_max;
|
||||
|
||||
if (!packet_validate_id((const uint8_t *) json_server_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!strcmp(json_server_id, (const char *) server_id)) {
|
||||
fprintf(stderr, "R %s: Attempt to receive json data from our own server ID (%s); loop!\n", packet->source_id, server_id);
|
||||
return false;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "uuid.h"
|
||||
|
||||
#include "packet.h"
|
||||
|
||||
@@ -47,8 +51,24 @@ uint32_t packet_rssi_scale_out(uint32_t value, uint32_t max) {
|
||||
}
|
||||
|
||||
void packet_sanity_check(const struct packet *packet) {
|
||||
assert(packet->source_id);
|
||||
assert(packet_validate_id(packet->source_id));
|
||||
assert(packet->type > PACKET_TYPE_NONE && packet->type < NUM_TYPES);
|
||||
assert(packet->mlat_timestamp <= PACKET_MLAT_MAX);
|
||||
assert(packet->rssi <= PACKET_RSSI_MAX);
|
||||
}
|
||||
|
||||
bool packet_validate_id(const uint8_t *id) {
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < UUID_LEN; i++) {
|
||||
uint8_t c = id[i];
|
||||
if (c == 0) {
|
||||
return true;
|
||||
}
|
||||
if (c < 32 || c > 126) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define PACKET_DATA_LEN_MAX 14
|
||||
@@ -34,3 +35,4 @@ uint32_t __attribute__ ((warn_unused_result)) packet_rssi_scale_in(uint32_t, uin
|
||||
uint32_t __attribute__ ((warn_unused_result)) packet_rssi_scale_out(uint32_t, uint32_t);
|
||||
|
||||
void packet_sanity_check(const struct packet *);
|
||||
bool __attribute__ ((warn_unused_result)) packet_validate_id(const uint8_t *);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "buf.h"
|
||||
#include "packet.h"
|
||||
#include "server.h"
|
||||
#include "uuid.h"
|
||||
|
||||
#include "adsb.pb-c.h"
|
||||
#include "proto.h"
|
||||
@@ -99,6 +100,9 @@ static bool proto_parse_packet(AdsbPacket *in, struct packet *packet, struct pro
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!packet_validate_id((const uint8_t *) in->source_id)) {
|
||||
return false;
|
||||
}
|
||||
packet->source_id = (uint8_t *) in->source_id;
|
||||
memcpy(packet->payload, in->payload.data, len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user