Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derflocki/3c581aafc5c3134ee2f2cb151a364035 to your computer and use it in GitHub Desktop.
Save derflocki/3c581aafc5c3134ee2f2cb151a364035 to your computer and use it in GitHub Desktop.
FROM php:7-cli
WORKDIR /xdebug
RUN yes | pecl install xdebug
RUN printf 'zend_extension="xdebug.so"\nxdebug.remote_enable=1\nxdebug.remote_log=/dev/stderr\nxdebug.remote_autostart=1\nxdebug.remote_connect_back=1\nxdebug.remote_host=doesnotexist2\nxdebug.remote_port=9003\nxdebug.remote_addr_header=HTTP_I_LIKE_COOKIES' >> /usr/local/etc/php/conf.d/xdebug.ini
RUN echo "<?php echo json_encode(\$_SERVER, JSON_PRETTY_PRINT);" > /var/www/html/bug.php
WORKDIR /var/www/html
test:
docker build --tag xdebug-remote_connect_back-bug .
docker run -d --rm --name xdebug-remote_connect_back-bug_1 xdebug-remote_connect_back-bug php -S 127.0.0.1:80
docker exec xdebug-remote_connect_back-bug_1 curl -s 127.0.0.1/bug.php -H "Cookie: XDBEUG_SESSION=" -H "I_LIKE_COOKIES: 10.0.0.1, 10.0.0.2" | grep HTTP_I_LIKE_COOKIES
docker kill xdebug-remote_connect_back-bug_1
diff --git a/xdebug_com.c b/xdebug_com.c
index 4ded60f7..683c2ae6 100644
--- a/xdebug_com.c
+++ b/xdebug_com.c
@@ -413,11 +413,15 @@ static void xdebug_init_debugger()
if (remote_addr) {
/* Use first IP according to RFC 7239 */
char *cp = strchr(Z_STRVAL_P(remote_addr), ',');
- if (cp) {
+ int cp_found = (cp != NULL);
+ if (cp_found) {
*cp = '\0';
}
XDEBUG_LOG_PRINT(XG(remote_log_file), "[%ld] I: Remote address found, connecting to %s:%ld.\n", pid, Z_STRVAL_P(remote_addr), (long int) XG(remote_port));
XG(context).socket = xdebug_create_socket(Z_STRVAL_P(remote_addr), XG(remote_port), XG(remote_connect_timeout));
+if (cp_found) {
+ *cp = ',';
+ }
} else {
XDEBUG_LOG_PRINT(XG(remote_log_file), "[%ld] W: Remote address not found, connecting to configured address/port: %s:%ld. :-|\n", pid, XG(remote_host), (long int) XG(remote_port));
XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port), XG(remote_connect_timeout));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment