Skip to content

Commit a7739be

Browse files
committed
Fixed bug #77722
1 parent 95c8f67 commit a7739be

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fixed bug #77345 (Stack Overflow caused by circular reference in garbage
1010
collection). (Alexandru Patranescu, Nikita, Dmitry)
1111

12+
- CLI Server:
13+
. Fixed bug #77722 (Incorrect IP set to $_SERVER['REMOTE_ADDR'] on the
14+
localhost). (Nikita)
15+
1216
- Apache2Handler:
1317
. Fixed bug #77648 (BOM in sapi/apache2handler/php_functions.c). (cmb)
1418

sapi/cli/php_cli_server.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,14 @@ static void sapi_cli_server_register_variables(zval *track_vars_array) /* {{{ */
637637
char *tmp;
638638
if ((tmp = strrchr(client->addr_str, ':'))) {
639639
char addr[64], port[8];
640+
const char *addr_start = client->addr_str, *addr_end = tmp;
641+
if (addr_start[0] == '[') addr_start++;
642+
if (addr_end[-1] == ']') addr_end--;
643+
640644
strncpy(port, tmp + 1, 8);
641645
port[7] = '\0';
642-
strncpy(addr, client->addr_str, tmp - client->addr_str);
643-
addr[tmp - client->addr_str] = '\0';
646+
strncpy(addr, addr_start, addr_end - addr_start);
647+
addr[addr_end - addr_start] = '\0';
644648
sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", addr);
645649
sapi_cli_server_register_variable(track_vars_array, "REMOTE_PORT", port);
646650
} else {

0 commit comments

Comments
 (0)