/* Add our data to buffer */
if(c->status.encryptout) {
- char outbuf[length];
size_t outlen = length;
- if(!cipher_encrypt(&c->outcipher, outbuf, length, buffer_prepare(&c->outbuf, length), &outlen, false) || outlen != length) {
+ if(!cipher_encrypt(&c->outcipher, buffer, length, buffer_prepare(&c->outbuf, length), &outlen, false) || outlen != length) {
logger(LOG_ERR, "Error while encrypting metadata to %s (%s)",
c->name, c->hostname);
return false;
}
bool receive_meta(connection_t *c) {
- int inlen, reqlen;
+ int inlen;
char inbuf[MAXBUFSIZE];
char *bufp = inbuf, *endp;
- If not, keep stuff in buffer and exit.
*/
+ buffer_compact(&c->inbuf, MAXBUFSIZE);
+
+ if(sizeof inbuf <= c->inbuf.len) {
+ logger(LOG_ERR, "Input buffer full for %s (%s)", c->name, c->hostname);
+ return false;
+ }
+
inlen = recv(c->socket, inbuf, sizeof inbuf - c->inbuf.len, 0);
if(inlen <= 0) {
if(c->tcplen) {
char *tcpbuffer = buffer_read(&c->inbuf, c->tcplen);
if(tcpbuffer) {
+ c->tcplen = 0;
receive_tcppacket(c, tcpbuffer, c->tcplen);
continue;
} else {