php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23812 Error (warning) in Net_DNS v. 1.00b1
Submitted: 2003-05-26 09:24 UTC Modified: 2003-05-26 13:37 UTC
From: colin at easydns dot com Assigned: pollita (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: colin at easydns dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-26 09:43 UTC] 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 13:37 UTC] pollita@php.net
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;
             }

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 20:03:34 2021 UTC