Skip to content

Commit 7daf2d8

Browse files
committed
Fix bug #79405 - gethostbyname() silently truncates after a null byte
1 parent 5174de7 commit 7daf2d8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

ext/standard/dns.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ PHP_FUNCTION(gethostbyaddr)
147147
zend_string *hostname;
148148

149149
ZEND_PARSE_PARAMETERS_START(1, 1)
150-
Z_PARAM_STRING(addr, addr_len)
150+
Z_PARAM_PATH(addr, addr_len)
151151
ZEND_PARSE_PARAMETERS_END();
152152

153153
hostname = php_gethostbyaddr(addr);
@@ -207,7 +207,7 @@ PHP_FUNCTION(gethostbyname)
207207
size_t hostname_len;
208208

209209
ZEND_PARSE_PARAMETERS_START(1, 1)
210-
Z_PARAM_STRING(hostname, hostname_len)
210+
Z_PARAM_PATH(hostname, hostname_len)
211211
ZEND_PARSE_PARAMETERS_END();
212212

213213
if (hostname_len > MAXFQDNLEN) {
@@ -230,7 +230,7 @@ PHP_FUNCTION(gethostbynamel)
230230
int i;
231231

232232
ZEND_PARSE_PARAMETERS_START(1, 1)
233-
Z_PARAM_STRING(hostname, hostname_len)
233+
Z_PARAM_PATH(hostname, hostname_len)
234234
ZEND_PARSE_PARAMETERS_END();
235235

236236
if (hostname_len > MAXFQDNLEN) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #76755 (setcookie does not accept "double" type for expire time)
3+
--FILE--
4+
<?php
5+
$host = "localhost\0.example.com";
6+
try {
7+
var_dump(gethostbyname($host));
8+
} catch(Error $e) {
9+
print $e->getMessage()."\n";
10+
}
11+
try {
12+
var_dump(gethostbynamel($host));
13+
} catch(Error $e) {
14+
print $e->getMessage()."\n";
15+
}
16+
?>
17+
--EXPECT--
18+
gethostbyname(): Argument #1 ($hostname) must not contain any null bytes
19+
gethostbynamel(): Argument #1 ($hostname) must not contain any null bytes

0 commit comments

Comments
 (0)