Skip to content

Commit

Permalink
Fix infinite loop in vnstat.php
Browse files Browse the repository at this point in the history
`popen()` can return `false` (something went wrong) or `null` (e.g. `popen()` is disabled), what results in a infinite loop when executing `while (!feof($fd) {}`
  • Loading branch information
PhrozenByte committed Jan 31, 2016
1 parent 572620b commit 5127a2f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions vnstat.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,26 @@ function get_vnstat_data($use_label=true)
global $iface, $vnstat_bin, $data_dir;
global $hour,$day,$month,$top,$summary;

$vnstat_data = array();
if (!isset($vnstat_bin) || $vnstat_bin == '')
{
if (file_exists("$data_dir/vnstat_dump_$iface"))
{
$vnstat_data = file("$data_dir/vnstat_dump_$iface");
}
else
{
$vnstat_data = array();
}
}
else
{
$fd = popen("$vnstat_bin --dumpdb -i $iface", "r");
$buffer = '';
while (!feof($fd)) {
$buffer .= fgets($fd);
if (is_resource($fd))
{
$buffer = '';
while (!feof($fd)) {
$buffer .= fgets($fd);
}
$vnstat_data = explode("\n", $buffer);
pclose($fd);
}
$vnstat_data = explode("\n", $buffer);
pclose($fd);
}


Expand All @@ -123,7 +123,7 @@ function get_vnstat_data($use_label=true)
$month = array();
$top = array();

if (strpos($vnstat_data[0], 'Error') !== false) {
if (isset($vnstat_data[0]) && strpos($vnstat_data[0], 'Error') !== false) {
return;
}

Expand Down

0 comments on commit 5127a2f

Please sign in to comment.