com php-src: Fixed bug #75097 (gethostname fails if your host name is 64 chars long): NEWS ext/standard/dns.c

From: Date: Sat, 19 Aug 2017 19:31:54 +0000
Subject: com php-src: Fixed bug #75097 (gethostname fails if your host name is 64 chars long): NEWS ext/standard/dns.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-99113@lists.php.net to get a copy of this message
Commit: 61538ebadc2ac80b29d6b7a9c355615fe0f40492 Author: Andrea Faulds <ajf@ajf.me> Sat, 19 Aug 2017 20:31:54 +0100 Parents: 3cad07b84fdf8a1ae87cae1a92da12f6f556bdd1 Branches: PHP-7.0 PHP-7.1 PHP-7.2 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=61538ebadc2ac80b29d6b7a9c355615fe0f40492 Log: Fixed bug #75097 (gethostname fails if your host name is 64 chars long) 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. Bugs: https://bugs.php.net/75097 Changed paths: M NEWS M ext/standard/dns.c Diff: diff --git a/NEWS b/NEWS index 84e0ebc..ee4ffab 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/ext/standard/dns.c b/ext/standard/dns.c index e060469..d7513e0 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -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; }

« previous php.cvs (#99113) next »