Bug #75097 [Csd]: gethostname fails if your host name is 64 chars long

From: Date: Sat, 19 Aug 2017 19:58:24 +0000
Subject: Bug #75097 [Csd]: gethostname fails if your host name is 64 chars long
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210747@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75097&edit=1 ID: 75097 User updated by: james at jmbtechnology dot co dot uk Reported by: james at jmbtechnology dot co dot uk Summary: gethostname fails if your host name is 64 chars long Status: Closed Type: Bug Package: Network related Operating System: Ubuntu 17.04 PHP Version: 7.0.22 Block user comment: N Private report: N New Comment: Thanks Andrea! :-) Previous Comments: ------------------------------------------------------------------------ [2017-08-19 19:39:17] ajf@php.net Automatic comment on behalf of ajf@ajf.me Revision: http://git.php.net/?p=php-src.git;a=commit;h=61538ebadc2ac80b29d6b7a9c355615fe0f40492 Log: Fixed bug #75097 (gethostname fails if your host name is 64 chars long) ------------------------------------------------------------------------ [2017-08-19 19:01:52] james at jmbtechnology dot co dot uk Description: ------------ A PHP library recently started running gethostname() on my live production server, and crashing with the error: PHP Warning: gethostname(): unable to fetch host [36]: File name too long in /thePHPFile.php on line 17 Googling lead me to: https://bugzilla.redhat.com/show_bug.cgi?id=1097665 And the following comment: "According to my tests, this is more +-1 error than anything else. The problem is relevant only when the hostname is precisely 64 bytes long, in which case gethostname(lname, MAXHOSTNAMELEN) (where MAXHOSTNAMELEN is 64) can not accomodate terminating byte. " I checked, and the host name was exactly 64 chars! The staging server hostname was not, and the library ran fine there. Quickly, I renamed the live server hostname to be 63 characters and it worked fine! Tested on a VM I had to - see test script. I don't know enough to know if this is a upstream bug - sorry! But as the effect manifests in PHP, it seemed worth reporting. Also can't currently test if this occurs in latest version of PHP - sorry again - but if I get anywhere with that later will update. Test script: --------------- Test it failing vagrant@vagrant:/vagrant/build$ sudo hostname 1234567890123456789012345678901234567890123456789012345678901234 sudo: unable to resolve host 12345678901234567890123456789012345678901234567890123456789012 vagrant@vagrant:/vagrant/build$ php /home/vagrant/test.php PHP Warning: gethostname(): unable to fetch host [36]: File name too long in /home/vagrant/test.php on line 3 Test it passing vagrant@vagrant:/vagrant/build$ sudo hostname 123456789012345678901234567890123456789012345678901234567890 sudo: unable to resolve host 1234567890123456789012345678901234567890123456789012345678901234 vagrant@vagrant:/vagrant/build$ php /home/vagrant/test.php 123456789012345678901234567890123456789012345678901234567890vagrant@vagrant:/vagrant/build$ And some background info vagrant@vagrant:/vagrant/build$ vagrant@vagrant:/vagrant/build$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Release: 16.04 Codename: xenial vagrant@vagrant:/vagrant/build$ php -v PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies vagrant@vagrant:/vagrant/build$ cat /home/vagrant/test.php <?php echo gethostname(); Expected result: ---------------- Expect gethostname() to return result even with long host names. Actual result: -------------- PHP Warning: gethostname(): unable to fetch host [36]: File name too long in /home/vagrant/test.php on line 3 And nothing returned ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75097&edit=1

« previous php.bugs (#210747) next »