From 4f824bec7845c75c60b957f8b44d598d2e2efcc7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Feb 2020 08:41:06 +0000 Subject: [PATCH] Fix potential code injection on MAC address validator Co-authored-by: DL6ER Signed-off-by: Adam Warner --- scripts/pi-hole/php/savesettings.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 6804f6a8..8ea24bf8 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -53,7 +53,15 @@ function validDomainWildcard($domain_name) function validMAC($mac_addr) { // Accepted input format: 00:01:02:1A:5F:FF (characters may be lower case) - return (preg_match('/([a-fA-F0-9]{2}[:]?){6}/', $mac_addr) == 1); + return !filter_var($mac_addr, FILTER_VALIDATE_MAC) === false; +} + +function formatMAC($mac_addr) +{ + preg_match("/([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})/", $mac_addr, $matches); + if(count($matches) > 0) + return $matches[0]; + return null; } function validEmail($email)