Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0

Bug #19569 endless loop in Socket/Streams.php
Submitted: 2012-08-17 00:53 UTC
From: ollil Assigned: mikepultz
Status: Closed Package: Net_DNS2
PHP Version: 5.4.5 OS: FreeBSD 9
Roadmaps: (Not assigned)    
Subscription  


 [2012-08-17 00:53 UTC] ollil (Oliver Lehmann)
Description: ------------ Hi, I upgraded today from Net DNS2 1.2.1 to 1.2.2 and when I now login to my local Horde IMP installation, it just keeps loading and loading in my browser without getting any response back. When I excange /Net/DNS2/Socket/Streams.php with the old 1.2.1 version it works again without any problems. Version 1.2.2 of the file introduced a while(1) loop and I would guess this renders the system being captured in those endless loop never reaching any break conditions. The problem is easy to detect if you have a look at how the while loop works. - define $chunk_size with length (in my case 512) - enter the while loop and read from the socket $chunk_size (512 in my case) - reduce $chunk_size by the length of $chunk (in my case 478) - $chunk_size is now 34 - fread 34 bytes this fread will now loop forever, as those 34 bytes can just not be read from the socket any more as there are just no 34 remaining bytes. An additional fread should not be done if the last fread returned less bytes than requested probably? UDP is used here, so $length is "hardcoded" to Net_DNS2_Lookups::DNS_MAX_UDP_SIZE The nameserver is running BIND 9.9.1-P2 if this is of any interest Test script: --------------- <?php require_once 'Net/DNS2.php'; $dns = new Net_DNS2_Resolver(); $dns->setServers('/etc/resolv.conf'); $host = empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_FORWARDED_FOR']; try { if ($response = $dns->query($host, 'PTR')) { foreach ($response->answer as $val) { if (isset($val->ptrdname)) { $ptrdname = $val->ptrdname; break; } } } } catch (Net_DNS2_Exception $e) {}; echo $ptrdname; ?> Expected result: ---------------- the hostname of my clients IP Actual result: -------------- nothing

Comments

 [2012-08-17 03:43 UTC] mikepultz (Mike Pultz)
-Status: Open +Status: Verified
Yeah- that's not good- Can you try a fix I've made? You just need this one file: http://code.google.com/p/netdns2/source/browse/trunk/Net/DNS2/Socket/Streams.ph p?spec=svn165&r=165 Mike
 [2012-08-17 12:59 UTC] ollil (Oliver Lehmann)
Revision 165 works!
 [2012-08-18 03:09 UTC] mikepultz (Mike Pultz)
-Status: Verified +Status: Closed -Assigned To: +Assigned To: mikepultz
Ok- I've added release v1.2.3 that includes this fix. You can grab it from PEAR or from the Google code page http://code.google.com/p/netdns2/downloads/list Mike