Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
FROM php:7-cli
WORKDIR /xdebug
RUN yes | pecl install xdebug
RUN printf 'zend_extension=""\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
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
docker exec xdebug-remote_connect_back-bug_1 curl -s -H "Cookie: XDBEUG_SESSION=" -H "I_LIKE_COOKIES:," | 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