* under the License.
*/
+#define __STDC_FORMAT_MACROS
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
case SOCKET_RECV_FRAMING:
union {
uint8_t buf[sizeof(uint32_t)];
- int32_t size;
+ uint32_t size;
} framing;
// if we've already received some bytes we kept them here
}
readWant_ = ntohl(framing.size);
- if (static_cast<int>(readWant_) <= 0) {
- GlobalOutput.printf("TConnection:workSocket() Negative frame size %d, remote side not using TFramedTransport?", static_cast<int>(readWant_));
+ if (readWant_ > server_->getMaxFrameSize()) {
+ // Don't allow giant frame sizes. This prevents bad clients from
+ // causing us to try and allocate a giant buffer.
+ GlobalOutput.printf("TNonblockingServer: frame size too large "
+ "(%"PRIu32" > %zu) from client %s. remote side not "
+ "using TFramedTransport?",
+ readWant_, server_->getMaxFrameSize(),
+ tSocket_->getSocketInfo().c_str());
close();
return;
}
/// Default limit on size of idle connection pool
static const size_t CONNECTION_STACK_LIMIT = 1024;
+ /// Default limit on frame size
+ static const int MAX_FRAME_SIZE = 256 * 1024 * 1024;
+
/// Default limit on total number of connected sockets
static const int MAX_CONNECTIONS = INT_MAX;
/// Limit for number of open connections
size_t maxConnections_;
+ /// Limit for frame size
+ size_t maxFrameSize_;
+
/// Time in milliseconds before an unperformed task expires (0 == infinite).
int64_t taskExpireTime_;
connectionStackLimit_ = CONNECTION_STACK_LIMIT;
maxActiveProcessors_ = MAX_ACTIVE_PROCESSORS;
maxConnections_ = MAX_CONNECTIONS;
+ maxFrameSize_ = MAX_FRAME_SIZE;
taskExpireTime_ = 0;
overloadHysteresis_ = 0.8;
overloadAction_ = T_OVERLOAD_NO_ACTION;
maxActiveProcessors_ = maxActiveProcessors;
}
+ /**
+ * Get the maximum allowed frame size.
+ *
+ * If a client tries to send a message larger than this limit,
+ * its connection will be closed.
+ *
+ * @return Maxium frame size, in bytes.
+ */
+ size_t getMaxFrameSize() const {
+ return maxFrameSize_;
+ }
+
+ /**
+ * Set the maximum allowed frame size.
+ *
+ * @param maxFrameSize The new maximum frame size.
+ */
+ void setMaxFrameSize(size_t maxFrameSize) {
+ maxFrameSize_ = maxFrameSize;
+ }
+
/**
* Get fraction of maximum limits before an overload condition is cleared.
*