Browse Source

Check for oversized client message before doing any reads to avoid possibility of exactly the wrong size buffer to ever invalidate the client, adding more info to a downgraded message

master
Con Kolivas 10 years ago
parent
commit
68e44be3ce
  1. 14
      src/connector.c

14
src/connector.c

@ -354,6 +354,12 @@ static void parse_client_msg(cdata_t *cdata, client_instance_t *client)
json_t *val;
retry:
if (unlikely(client->bufofs > MAX_MSGSIZE)) {
LOGNOTICE("Client id %"PRId64" fd %d overloaded buffer without EOL, disconnecting",
client->id, client->fd);
invalidate_client(ckp, cdata, client);
return;
}
buflen = PAGESIZE - client->bufofs;
/* This read call is non-blocking since the socket is set to O_NOBLOCK */
ret = read(client->fd, client->buf + client->bufofs, buflen);
@ -368,14 +374,8 @@ retry:
client->bufofs += ret;
reparse:
eol = memchr(client->buf, '\n', client->bufofs);
if (!eol) {
if (unlikely(client->bufofs > MAX_MSGSIZE)) {
LOGWARNING("Client fd %d overloaded buffer without EOL, disconnecting", client->fd);
invalidate_client(ckp, cdata, client);
return;
}
if (!eol)
goto retry;
}
/* Do something useful with this message now */
buflen = eol - client->buf + 1;

Loading…
Cancel
Save