mikepultz / netdns2

Native PHP DNS Resolver and Updater
https://netdns2.com/
Other
119 stars 64 forks source link

Better check of data-len #137

Closed chaosben closed 1 year ago

chaosben commented 1 year ago

The length check here: https://github.com/mikepultz/netdns2/blob/1284c4b1f0a0e1fe087b4fec7dff960d0527e273/Net/DNS2/Socket.php#L363

should be change to

if (strlen($data) < 2) {

in order to raise the correct error.

At the moment a warning/error (depending on php version) is raised here: https://github.com/mikepultz/netdns2/blob/1284c4b1f0a0e1fe087b4fec7dff960d0527e273/Net/DNS2/Socket.php#L369 if the data returned has the length of one byte.

Some servers answer with one byte and because of that the following code in the read-function loops endless.

Code to reproduce:

require 'vendor/autoload.php';

$resolver = new Net_DNS2_Resolver(['nameservers' => ['195.191.93.140']]); //nameserver of backupheld.de

$result = $resolver->query('backupheld.de', 'AXFR');
mikepultz commented 1 year ago

Thanks @chaosben - I haven't been able to reproduce this in any of my testing, but there's no harm in making this change- it will be included in v1.5.4.

Mike

chaosben commented 1 year ago

Thank you very much! 🤓