Added ckpeers function to check if the json array returned by api/v1/instance/peers is well formed

This commit is contained in:
pezcurrel 2022-12-26 14:12:06 +01:00
parent 3c1621df1d
commit 926b1b0d73

View file

@ -280,7 +280,7 @@ function crawl($list,$id) {
lecho(2,'could not load «'.$inst.s peers: '.$peers['emsg'].'.'.N);
} else {
$peers=@json_decode($peers['cont'],true);
if (!is_array($peers)) {
if (!is_array($peers) || !ckpeers($peers)) {
lecho(2,'loading «'.$inst.s peers, got not good JSON.'.N);
} else {
lecho(1,'successfully loaded «'.$inst.s peers :-)'.N);
@ -303,7 +303,6 @@ function crawl($list,$id) {
}
$whynot=[];
if (in_array($peer,$cinsts)) $whynot[]='it has already been checked';
if (!is_string($peer)) $whynot[]='its name is not a string';
if (!validhostname($peer)) $whynot[]='its name is not a valid hostname';
if (ckexarr($peer)) $whynot[]='its name matches an exclusion regexp';
if (in_array($peer,$list)) $whynot[]='it is already present in current list';
@ -340,6 +339,16 @@ function crawl($list,$id) {
lecho(1,'###### END OF ROUND '.$id.' ######'.N);
}
function ckpeers(&$arr) {
$i=0;
foreach ($arr as $key=>$val) {
if ($key!=$i || !is_string($val))
return(false);
$i++;
}
return(true);
}
function mexit($lev,$msg,$code,$remlock) {
global $link, $peersf, $cpeersf, $apeersf, $lockfp;
if (isset($link) && $link!==false) mysqli_close($link);