Minimal message validation

Prevent improperly formatted message from breaking into serious disaster
for running process.
This commit is contained in:
Andrey Borodin 2019-04-29 17:06:11 +05:00
parent 4198f2694d
commit 8abed18d69
3 changed files with 7 additions and 2 deletions

View File

@ -192,7 +192,12 @@ od_read(od_io_t *io, uint32_t time_ms)
uint32_t size;
size = kiwi_read_size((char*)&header, sizeof(header));
assert(size > 0);
if (size < sizeof(uint32_t) || header.type < 0x20) {
// This is not a postgres fe protocol v3 message
// We should drop connection ASAP
return NULL;
}
size -= sizeof(uint32_t);
machine_msg_t *msg;
msg = machine_msg_create(sizeof(header) + size);

View File

@ -189,6 +189,7 @@ od_relay_process(od_relay_t *relay, int *progress, char *data, int size)
int body;
body = kiwi_read_size(data, sizeof(kiwi_header_t));
body -= sizeof(uint32_t);
int total = sizeof(kiwi_header_t) + body;
if (size >= total) {

View File

@ -150,7 +150,6 @@ kiwi_read_size(char *data, uint32_t data_size)
/* size */
uint32_t size = 0;
kiwi_read32(&size, &pos, &pos_size);
size -= sizeof(uint32_t);
return size;
}