Fixes based on suggestions

I use the term socket for any extension, either unix socket, or internet socket (port).

I check if the socket is all digits
* only integers 0 and larger would pass this test.
I then check if the string is less than or equal to the maximum port number.

By using "if($socket)" I make sure socket isn't false, empty, or the string '0'.

I don't believe I need to initialize $port because $port will always be set if $socket is true. Please show me if I am wrong here. Thanks
This commit is contained in:
josh4trunks 2014-06-11 21:47:45 -07:00
parent 55ccd6da51
commit 1b02991a1d
1 changed files with 7 additions and 11 deletions

View File

@ -64,14 +64,10 @@ class OC_DB {
$pass = OC_Config::getValue( "dbpassword", "" ); $pass = OC_Config::getValue( "dbpassword", "" );
$type = OC_Config::getValue( "dbtype", "sqlite" ); $type = OC_Config::getValue( "dbtype", "sqlite" );
if(strpos($host, ':')) { if(strpos($host, ':')) {
list($host, $port)=explode(':', $host, 2); list($host, $socket)=explode(':', $host, 2);
if(!is_int($port)||$port<1||$port>65535) { $port = ctype_digit($socket) && $socket<=65535;
$socket=true;
} else {
$socket=false;
}
} else { } else {
$port=false; $socket=FALSE;
} }
$factory = new \OC\DB\ConnectionFactory(); $factory = new \OC\DB\ConnectionFactory();
@ -93,11 +89,11 @@ class OC_DB {
'host' => $host, 'host' => $host,
'dbname' => $name, 'dbname' => $name,
); );
if (!empty($port)) { if ($socket) {
if ($socket) { if ($port) {
$connectionParams['unix_socket'] = $port; $connectionParams['port'] = $socket;
} else { } else {
$connectionParams['port'] = $port; $connectionParams['unix_socket'] = $socket;
} }
} }
} }