Skip to content

Commit

Permalink
Fixed bug #75097 (gethostname fails if your host name is 64 chars long)
Browse files Browse the repository at this point in the history
PHP contained two different off-by-one errors, which are fixed here. First,
it created a buffer of size HOST_NAME_MAX, not adding space for a null
terminator. Second, it subtracted 1 from the size of that buffer when passing
its size to gethostname(), despite gethostname() expecting it to be a buffer
size including space for a terminating null byte, not a string length.
  • Loading branch information
hikari-no-yume committed Aug 19, 2017
1 parent 3cad07b commit 61538eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PHP NEWS
- CURL:
. Fixed bug #75093 (OpenSSL support not detected). (Remi)

- Standard:
. Fixed bug #75097 (gethostname fails if your host name is 64 chars long). (Andrea)

31 Aug 2017 PHP 7.0.23

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ static zend_string *php_gethostbyname(char *name);
Get the host name of the current machine */
PHP_FUNCTION(gethostname)
{
char buf[HOST_NAME_MAX];
char buf[HOST_NAME_MAX + 1];

if (zend_parse_parameters_none() == FAILURE) {
return;
}

if (gethostname(buf, sizeof(buf) - 1)) {
if (gethostname(buf, sizeof(buf))) {
php_error_docref(NULL, E_WARNING, "unable to fetch host [%d]: %s", errno, strerror(errno));
RETURN_FALSE;
}
Expand Down

0 comments on commit 61538eb

Please sign in to comment.