/*
meta.c -- handle the meta communication
- Copyright (C) 2000-2014 Guus Sliepen <guus@tinc-vpn.org>,
+ Copyright (C) 2000-2017 Guus Sliepen <guus@tinc-vpn.org>,
2000-2005 Ivo Timmermans
2006 Scott Lamb <slamb@slamb.org>
int outlen;
int result;
- if(!c) {
- logger(LOG_ERR, "send_meta() called with NULL pointer!");
- abort();
- }
-
ifdebug(META) logger(LOG_DEBUG, "Sending %d bytes of metadata to %s (%s)", length,
c->name, c->hostname);
/* Add our data to buffer */
if(c->status.encryptout) {
+ /* Check encryption limits */
+ if(length > c->outbudget) {
+ ifdebug(META) logger(LOG_ERR, "Byte limit exceeded for encryption to %s (%s)", c->name, c->hostname);
+ return false;
+ } else {
+ c->outbudget -= length;
+ }
+
result = EVP_EncryptUpdate(c->outctx, (unsigned char *)c->outbuf + c->outbufstart + c->outbuflen,
&outlen, (unsigned char *)buffer, length);
if(!result || outlen < length) {
} else if(errno == EINTR) {
continue;
} else if(sockwouldblock(sockerrno)) {
- ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Flushing %d bytes to %s (%s) would block",
+ ifdebug(META) logger(LOG_DEBUG, "Flushing %d bytes to %s (%s) would block",
c->outbuflen, c->name, c->hostname);
return true;
} else {
/* Decrypt */
if(c->status.decryptin && !decrypted) {
+ /* Check decryption limits */
+ if(lenin > c->inbudget) {
+ ifdebug(META) logger(LOG_ERR, "Byte limit exceeded for decryption from %s (%s)", c->name, c->hostname);
+ return false;
+ } else {
+ c->inbudget -= lenin;
+ }
+
result = EVP_DecryptUpdate(c->inctx, (unsigned char *)inbuf, &lenout, (unsigned char *)c->buffer + oldlen, lenin);
if(!result || lenout != lenin) {
logger(LOG_ERR, "Error while decrypting metadata from %s (%s): %s",