]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix Windows-only postmaster code to reject a connection request and continue,
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 6 Jan 2006 02:58:40 +0000 (02:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 6 Jan 2006 02:58:40 +0000 (02:58 +0000)
rather than elog(FATAL), when there is no more room in ShmemBackendArray.
This is a security issue since too many connection requests arriving close
together could cause the postmaster to shut down, resulting in denial of
service.  Reported by Yoshiyuki Asaba, fixed by Magnus Hagander.

src/backend/postmaster/postmaster.c

index 8b316197fc13511ed043744b8167c08f9316472f..bc7e543242d6276b5137e5eb39c2f17c2901c55f 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.4 2005/11/05 03:05:04 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.5 2006/01/06 02:58:40 tgl Exp $
  *
  * NOTES
  *
@@ -144,7 +144,11 @@ typedef struct bkend
 static Dllist *BackendList;
 
 #ifdef EXEC_BACKEND
-#define NUM_BACKENDARRAY_ELEMS (2*MaxBackends)
+/* 
+ * Number of entries in the backend table. Twice the number of backends,
+ * plus four other subprocesses (stats, bgwriter, autovac, logger). 
+ */
+#define NUM_BACKENDARRAY_ELEMS (2*MaxBackends + 4)
 static Backend *ShmemBackendArray;
 #endif
 
@@ -3018,6 +3022,15 @@ internal_forkexec(int argc, char *argv[], Port *port)
        Assert(strncmp(argv[1], "-fork", 5) == 0);
        Assert(argv[2] == NULL);
 
+       /* Verify that there is room in the child list */
+       if (win32_numChildren >= NUM_BACKENDARRAY_ELEMS)
+       {
+               elog(LOG, "no room for child entry in backend list");
+               /* Report same error as for a fork failure on Unix */
+               errno = EAGAIN;
+               return -1;
+       }
+
        /* Set up shared memory for parameter passing */
        ZeroMemory(&sa,sizeof(sa));
        sa.nLength = sizeof(sa);