From 1287d6ddb303fc9b088b8a6837490042a1540dc6 Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Tue, 26 Sep 2017 14:20:04 +0200
Subject: [PATCH] Only allow colons in db host for IPv6 addresses

Signed-off-by: Joas Schilling <coding@schilljs.com>
---
 lib/private/Setup.php | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 521a8f75f8e..6cef1eb861d 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -293,6 +293,10 @@ class Setup {
 			$error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
 		}
 
+		if (!$this->validateDatabaseHost($options['dbhost'])) {
+			$error[] = $l->t('Given database host is invalid and must not contain the port: %s', [$options['dbhost']]);
+		}
+
 		if(count($error) != 0) {
 			return $error;
 		}
@@ -410,6 +414,18 @@ class Setup {
 		return $error;
 	}
 
+	/**
+	 * @param string $host
+	 * @return bool
+	 */
+	protected function validateDatabaseHost($host) {
+		if (strpos($host, ':') === false) {
+			return true;
+		}
+
+		return filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
+	}
+
 	public static function installBackgroundJobs() {
 		\OC::$server->getJobList()->add('\OC\Authentication\Token\DefaultTokenCleanupJob');
 	}
-- 
GitLab