From 14dd1350df08cb1cc471a3abf75ebf241c48d192 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 23 Apr 2020 11:27:24 +0200 Subject: [PATCH] Strip whitespaces from the beginning and end of user input to prevent errors getting triggered due to users trying to add "empty" domains. Signed-off-by: DL6ER --- scripts/pi-hole/php/groups.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 2167295e..3a7d09d5 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -54,7 +54,7 @@ if ($_POST['action'] == 'get_groups') { } elseif ($_POST['action'] == 'add_group') { // Add new group try { - $names = explode(' ', $_POST['name']); + $names = explode(' ', trim($_POST['name'])); $stmt = $db->prepare('INSERT INTO "group" (name,description) VALUES (:name,:desc)'); if (!$stmt) { throw new Exception('While preparing statement: ' . $db->lastErrorMsg()); @@ -234,7 +234,7 @@ if ($_POST['action'] == 'get_groups') { } elseif ($_POST['action'] == 'add_client') { // Add new client try { - $ips = explode(' ', $_POST['ip']); + $ips = explode(' ', trim($_POST['ip'])); $stmt = $db->prepare('INSERT INTO client (ip,comment) VALUES (:ip,:comment)'); if (!$stmt) { throw new Exception('While preparing statement: ' . $db->lastErrorMsg()); @@ -410,7 +410,7 @@ if ($_POST['action'] == 'get_groups') { } elseif ($_POST['action'] == 'add_domain') { // Add new domain try { - $domains = explode(' ', $_POST['domain']); + $domains = explode(' ', trim($_POST['domain'])); $stmt = $db->prepare('INSERT INTO domainlist (domain,type,comment) VALUES (:domain,:type,:comment)'); if (!$stmt) { throw new Exception('While preparing statement: ' . $db->lastErrorMsg()); @@ -604,7 +604,7 @@ if ($_POST['action'] == 'get_groups') { } elseif ($_POST['action'] == 'add_adlist') { // Add new adlist try { - $addresses = explode(' ', $_POST['address']); + $addresses = explode(' ', trim($_POST['address'])); $stmt = $db->prepare('INSERT INTO adlist (address,comment) VALUES (:address,:comment)'); if (!$stmt) {