Skip to content

Commit 6998c1a

Browse files
committed
fastcgi: fcgi_listen(), disallow SO_REUSEADDR socket option on windows.
To increase security, we trade off performance on failures, see comment for the reasoning behind.
1 parent 98e0dbc commit 6998c1a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

main/fastcgi.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,13 @@ int fcgi_listen(const char *path, int backlog)
747747

748748
/* Create, bind socket and start listen on it */
749749
if ((listen_socket = socket(sa.sa.sa_family, SOCK_STREAM, 0)) < 0 ||
750-
#ifdef SO_REUSEADDR
750+
#if !defined(_WIN32) && defined(SO_REUSEADDR)
751+
/* SO_REUSEADDR on windows has a different behavior compared to unixes.
752+
* It potentially allow a same address/port combination, even from an active connection (aka port hijacking).
753+
* We trade the "fast port reuse on failure" ability though but performance ought to take a backseat on this matter.
754+
* It might be tempting to use SO_EXCLUSIVEADDRINUSE, but it can significantly increase the amount of binding failures
755+
* without real benefits .. but it is open for discussions.
756+
*/
751757
setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse)) < 0 ||
752758
#endif
753759
bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 ||

0 commit comments

Comments
 (0)