Skip to content

Commit

Permalink
Fixed issue #1484: Use FD_CLOEXEC to prevent debugging FDs from leaki…
Browse files Browse the repository at this point in the history
…ng to forked processes
  • Loading branch information
DaveRandom committed Oct 27, 2017
1 parent 4201879 commit 0734ec1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions xdebug_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ static int xdebug_create_socket_unix(const char *path TSRMLS_DC)
return (errno == EACCES) ? SOCK_ACCESS_ERR : SOCK_ERR;
}

/* Prevent the socket from being inherited by exec'd children */
if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) {
XDEBUG_LOG_PRINT(XG(remote_log_file), "W: Creating socket for 'unix://%s', fcntl(FD_CLOEXEC): %s.\n", path, strerror(errno));
}

return sockfd;
}
#endif
Expand Down Expand Up @@ -157,6 +162,13 @@ int xdebug_create_socket(const char *hostname, int dport TSRMLS_DC)
fcntl(sockfd, F_SETFL, O_NONBLOCK);
#endif

#if !WIN32 && !WINNT
/* Prevent the socket from being inherited by exec'd children on *nix (not necessary on Win) */
if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) {
XDEBUG_LOG_PRINT(XG(remote_log_file), "W: Creating socket for '%s:%d', fcntl(FD_CLOEXEC): %s.\n", hostname, dport, strerror(errno));
}
#endif

/* Try to connect to the newly created socket */
/* Worth noting is that the port is set in the getaddrinfo call before */
status = connect(sockfd, ptr->ai_addr, ptr->ai_addrlen);
Expand Down

0 comments on commit 0734ec1

Please sign in to comment.