From 7392aa13eb03ea73888680a547b23625a2a27f5c Mon Sep 17 00:00:00 2001
From: Nathan Rennie-Waldock <nathan.renniewaldock@gmail.com>
Date: Sun, 25 Dec 2022 03:23:19 +0000
Subject: [PATCH] Fix exception when deleting a section containing no subnets
 in PHP 8.0+

Signed-off-by: Nathan Rennie-Waldock <nathan.renniewaldock@gmail.com>
---
 app/admin/sections/edit-result.php   | 2 +-
 functions/classes/class.Sections.php | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/admin/sections/edit-result.php b/app/admin/sections/edit-result.php
index c0b54fe9..ecbf01d3 100755
--- a/app/admin/sections/edit-result.php
+++ b/app/admin/sections/edit-result.php
@@ -64,7 +64,7 @@ if ($_POST['action']=="delete" && !isset($_POST['deleteconfirm'])) {
 	# no subsections
 	else {
 		$subnets  = $Subnets->fetch_section_subnets ($_POST['id']);			//fetch all subnets in section
-		$num_subnets = sizeof($subnets);
+		$num_subnets = is_array($subnets) ? sizeof($subnets) : 0;
 		$ipcnt = $Addresses->count_addresses_in_multiple_subnets($subnets);
 	}
 
diff --git a/functions/classes/class.Sections.php b/functions/classes/class.Sections.php
index 92f2f5ce..e2fe3983 100644
--- a/functions/classes/class.Sections.php
+++ b/functions/classes/class.Sections.php
@@ -169,7 +169,7 @@ class Sections extends Common_functions {
 		# truncate and delete all subnets in all sections, than delete sections
 		foreach($all_ids as $id) {
 			$section_subnets = $Subnets->fetch_section_subnets ($id);
-			if(sizeof($section_subnets)>0) {
+			if(is_array($section_subnets) && sizeof($section_subnets)>0) {
 				foreach($section_subnets as $ss) {
 					//delete subnet
 					$Subnets->modify_subnet("delete", array("id"=>$ss->id));
-- 
GitLab