pgpool2.git / summary / log / commit / refs
commit c7a7f22c0dd113e2bea067239c86f2d3d0aa1090
Author: Yoshiyuki Asaba <y-asaba at pgfoundry.org>
Date: Thu Oct 11 08:34:59 2007 +0000
Check startup packet length. If the length is greater than 10,000
byte, pgpool reject the connection.
child.c | 6 ++++++
pool.h | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/child.c b/child.c
index fdac154d9..d4d9567a7 100644
--- a/child.c
+++ b/child.c
@@ -922,6 +922,12 @@ static StartupPacket *read_startup_packet(POOL_CONNECTION *cp)
{
pool_error("read_startup_packet: incorrect packet length (%d)", len);
}
+ else if (len >= MAX_STARTUP_PACKET_LENGTH)
+ {
+ pool_error("read_startup_packet: invalid startup packet");
+ pool_free_startup_packet(sp);
+ return NULL;
+ }
sp->startup_packet = calloc(len, 1);
if (!sp->startup_packet)
diff --git a/pool.h b/pool.h
index 11cf96f15..fbeb8e385 100644
--- a/pool.h
+++ b/pool.h
@@ -83,6 +83,15 @@ typedef enum {
#define PROTO_MAJOR_V2 2
#define PROTO_MAJOR_V3 3
+/*
+ * In protocol 3.0 and later, the startup packet length is not fixed, but
+ * we set an arbitrary limit on it anyway. This is just to prevent simple
+ * denial-of-service attacks via sending enough data to run the server
+ * out of memory.
+ */
+#define MAX_STARTUP_PACKET_LENGTH 10000
+
+
typedef struct StartupPacket_v2
{
int protoVersion; /* Protocol version */
[parent: 99da073abcc4]