Bug #75097 [NEW]: gethostname fails if your host name is 64 chars long
| From: | james at jmbtechnology dot co dot uk | Date: | Sat, 19 Aug 2017 19:01:57 +0000 |
| Subject: | Bug #75097 [NEW]: gethostname fails if your host name is 64 chars long | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-210745@lists.php.net to get a copy of this message | ||
From: james at jmbtechnology dot co dot uk
Operating system: Ubuntu 17.04
PHP version: 7.0.22
Package: Network related
Bug Type: Bug
Bug description:gethostname fails if your host name is 64 chars long
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 bug report at https://bugs.php.net/bug.php?id=75097&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75097&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75097&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75097&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75097&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75097&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75097&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75097&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75097&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75097&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75097&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75097&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75097&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75097&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75097&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75097&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75097&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75097&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75097&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75097&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75097&r=mysqlcfg