From ed748aef157e34b5f4d02b47c4d755d15a330493 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 11 Feb 2026 13:23:15 +0100 Subject: [PATCH] mvc: catch empty data in CSV import Catch empty lines. A single "," will generate an empty string instead of NULL so we are good here. It's safe to assume we have at least one property in the line, otherwise the data is useless to us anyway. From the fgetcsv() manual: A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error. See: https://www.php.net/manual/en/function.fgetcsv.php --- .../controllers/OPNsense/Base/ApiMutableModelControllerBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php b/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php index 60256014e9..744cfbebca 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php @@ -674,7 +674,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase while (($line = fgetcsv($stream, null, $separator)) !== false) { if (empty($heading)) { $heading = $line; - } else { + } elseif (count($line) >= 1 && !is_null($line[0])) { $record = []; foreach ($line as $idx => $content) { if (isset($heading[$idx])) {