|
23 | 23 | #include "php_network.h" |
24 | 24 | #include "file.h" |
25 | 25 |
|
| 26 | +static size_t php_fsockopen_format_host_port(char **message, const char *prefix, size_t prefix_len, |
| 27 | + const char *host, size_t host_len, zend_long port) |
| 28 | +{ |
| 29 | + char portbuf[32]; |
| 30 | + int portlen = snprintf(portbuf, sizeof(portbuf), ":" ZEND_LONG_FMT, port); |
| 31 | + size_t total_len = prefix_len + host_len + portlen; |
| 32 | + |
| 33 | + char *result = emalloc(total_len + 1); |
| 34 | + |
| 35 | + if (prefix_len > 0) { |
| 36 | + memcpy(result, prefix, prefix_len); |
| 37 | + } |
| 38 | + memcpy(result + prefix_len, host, host_len); |
| 39 | + memcpy(result + prefix_len + host_len, portbuf, portlen); |
| 40 | + |
| 41 | + result[total_len] = '\0'; |
| 42 | + |
| 43 | + *message = result; |
| 44 | + |
| 45 | + return total_len; |
| 46 | +} |
| 47 | + |
26 | 48 | /* {{{ php_fsockopen() */ |
27 | 49 |
|
28 | 50 | static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) |
@@ -62,11 +84,12 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) |
62 | 84 | } |
63 | 85 |
|
64 | 86 | if (persistent) { |
65 | | - spprintf(&hashkey, 0, "pfsockopen__%s:" ZEND_LONG_FMT, host, port); |
| 87 | + php_fsockopen_format_host_port(&hashkey, "pfsockopen__", strlen("pfsockopen__"), host, |
| 88 | + host_len, port); |
66 | 89 | } |
67 | 90 |
|
68 | 91 | if (port > 0) { |
69 | | - hostname_len = spprintf(&hostname, 0, "%s:" ZEND_LONG_FMT, host, port); |
| 92 | + hostname_len = php_fsockopen_format_host_port(&hostname, "", 0, host, host_len, port); |
70 | 93 | } else { |
71 | 94 | hostname_len = host_len; |
72 | 95 | hostname = host; |
|
0 commit comments