|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-05-26 09:24 UTC] colin at easydns dot com
My logs started showing this: PHP Warning: unpack() [http://www.php.net/function.unpack]: Type n: not enough input, need 2, have 0 in /usr/local/lib/php/Net/DNS/Resolver.php on line 745 I think this diff will fix things: --- Resolver.php.orig 2003-05-26 10:18:52.000000000 -0400 +++ Resolver.php 2003-05-26 10:12:14.000000000 -0400 @@ -742,7 +742,7 @@ socket_set_timeout($sock, $timeout); $buf = fread($sock, 2); $e = socket_get_status($sock); - $len = unpack('nint', $buf); + $len = unpack('n2int', $buf); $len = $len['int']; if (!$len) { continue; - Colin PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
First, I do agree with your suggestion to supress warning messages on a failed fsockopen() since the class handles error reporting by itself. However, your submitted patch to modify the format parameter of unpack is just plain wrong. What the error message is saying is that $buf is empty, implying a failed read (no response from name server?). What your patch would do is simply make unpack expect 4 bytes rather than merely two. ('n' indicates a network order short which is already a 2 byte structure). In any event that line itself is fine, but warning/notices during that line and the line following need to be supressed so that the subsequent line examingin the value of $len can continue out of the loop and try the next name server. It's now fixed in CVS, here's the patch I applied: Index: Resolver.php =================================================================== RCS file: /repository/pear/Net_DNS/DNS/Resolver.php,v retrieving revision 1.15 diff -u -r1.15 Resolver.php --- Resolver.php 24 Feb 2003 21:44:32 -0000 1.15 +++ Resolver.php 26 May 2003 18:34:09 -0000 @@ -707,7 +707,7 @@ if (isset($this->sockets[$sock_key]) && is_resource($this->sockets[$sock_key])) { $sock = &$this->sockets[$sock_key]; } else { - if (! ($sock = fsockopen($ns, $dstport, $errno, + if (! ($sock = @fsockopen($ns, $dstport, $errno, $errstr, $timeout))) { $this->errorstring = 'connection failed'; if ($this->debug) { @@ -742,8 +742,10 @@ socket_set_timeout($sock, $timeout); $buf = fread($sock, 2); $e = socket_get_status($sock); - $len = unpack('nint', $buf); - $len = $len['int']; + /* If $buf is empty, we want to supress errors + long enough to reach the continue; down the line */ + $len = @unpack('nint', $buf); + $len = @$len['int']; if (!$len) { continue; }