Improve extfs incoming message reliability.
This commit is contained in:
parent
ec990882b0
commit
01afa43fb0
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#if defined(__sortix__)
|
#if defined(__sortix__)
|
||||||
|
|
||||||
|
#include <sys/mman.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -680,23 +681,24 @@ void HandleIncomingMessage(int chl, struct fsm_msg_header* hdr, Filesystem* fs)
|
||||||
RespondError(chl, ENOTSUP);
|
RespondError(chl, ENOTSUP);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint8_t* body = (uint8_t*) malloc(hdr->msgsize);
|
uint8_t body_buffer[65536];
|
||||||
if ( !body )
|
uint8_t* body = body_buffer;
|
||||||
|
if ( sizeof(body_buffer) < hdr->msgsize )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "extfs: message of type %zu too large: %zu bytes\n", hdr->msgtype, hdr->msgsize);
|
body = (uint8_t*) mmap(NULL, hdr->msgsize, PROT_READ | PROT_WRITE,
|
||||||
RespondError(chl, errno);
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
return;
|
if ( (void*) body == MAP_FAILED )
|
||||||
|
{
|
||||||
|
RespondError(chl, errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
size_t amount = readall(chl, body, hdr->msgsize);
|
if ( readall(chl, body, hdr->msgsize) == hdr->msgsize )
|
||||||
if ( amount < hdr->msgsize )
|
handlers[hdr->msgtype](chl, body, fs);
|
||||||
{
|
else
|
||||||
fprintf(stderr, "extfs: incomplete message of type %zu: got %zi of %zu bytes\n", hdr->msgtype, amount, hdr->msgsize);
|
|
||||||
RespondError(chl, errno);
|
RespondError(chl, errno);
|
||||||
free(body);
|
if ( sizeof(body_buffer) < hdr->msgsize )
|
||||||
return;
|
munmap(body, hdr->msgsize);
|
||||||
}
|
|
||||||
handlers[hdr->msgtype](chl, body, fs);
|
|
||||||
free(body);
|
|
||||||
}
|
}
|
||||||
static volatile bool should_terminate = false;
|
static volatile bool should_terminate = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue