#23812 [Asn->Csd]: Error (warning) in Net_DNS v. 1.00b1
| From: | pollita@php.net | Date: | Mon, 26 May 2003 18:37:01 +0000 |
| Subject: | #23812 [Asn->Csd]: Error (warning) in Net_DNS v. 1.00b1 | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16729@lists.php.net to get a copy of this message | ||
ID: 23812
Updated by: pollita@php.net
Reported By: colin at easydns dot com
-Status: Assigned
+Status: Closed
Bug Type: PEAR related
Operating System: Linux
PHP Version: 4.3.1
Assigned To: pollita
New Comment:
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;
}
Previous Comments:
------------------------------------------------------------------------
[2003-05-26 09:43:21] colin at easydns dot com
While you are at it, I think the fsockopen() command on line 710 of
Resolver.php needs to be changed to @fsockopen(), to surpress the
warnings for failed connections.
- Colin
------------------------------------------------------------------------
[2003-05-26 09:24:09] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23812&edit=1