diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 9d7e66ce2b5bc..d5c4888211135 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1918,10 +1918,17 @@ consult the installation file that came with this distribution, or visit \n\ #endif if (bindpath) { - int backlog = 128; + int backlog = MIN(SOMAXCONN, 128); if (getenv("PHP_FCGI_BACKLOG")) { backlog = atoi(getenv("PHP_FCGI_BACKLOG")); } + if (backlog < -1 || backlog > SOMAXCONN) { + fprintf(stderr, "Invalid backlog %d, needs to be between -1 and %d\n", backlog, SOMAXCONN); +#ifdef ZTS + tsrm_shutdown(); +#endif + return FAILURE; + } fcgi_fd = fcgi_listen(bindpath, backlog); if (fcgi_fd < 0) { fprintf(stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath);