Add check for unix socket path truncation

Don't allow unix socket path to be truncated 
parent 206e1dc6
...@@ -20,7 +20,8 @@ use strict; ...@@ -20,7 +20,8 @@ use strict;
use base qw(Exporter); use base qw(Exporter);
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
native_path posix_path mixed_path); native_path posix_path mixed_path
check_socket_path_length);
BEGIN { BEGIN {
if ($^O eq "cygwin") { if ($^O eq "cygwin") {
...@@ -50,6 +51,15 @@ BEGIN { ...@@ -50,6 +51,15 @@ BEGIN {
} }
} }
BEGIN {
if (eval "use IO::Socket::UNIX; 1") {
eval 'sub HAVE_UNIX_SOCKET { 1 }';
}
else {
eval 'sub HAVE_UNIX_SOCKET { 0 }';
}
}
# #
# native_path # native_path
...@@ -91,5 +101,33 @@ sub posix_path { ...@@ -91,5 +101,33 @@ sub posix_path {
} }
sub check_socket_path_length {
my ($path)= @_;
my $truncated= 0;
if (HAVE_UNIX_SOCKET){
require IO::Socket::UNIX;
my $sock = new IO::Socket::UNIX
(
Local => $path,
Listen => 1,
) or die $!;
if ($path ne $sock->hostpath()){
# Path was truncated
$truncated= 1;
# Output diagnostic messages
print "path: '$path', length: ", length($path) ,"\n";
print "hostpath: '", $sock->hostpath(),
"', length: ", length($sock->hostpath()), "\n";
}
$sock= undef;
unlink($path);
return $truncated;
};
# All paths OK!
return $truncated;
}
1; 1;
...@@ -606,6 +606,15 @@ sub command_line_setup { ...@@ -606,6 +606,15 @@ sub command_line_setup {
$opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir; $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
$opt_tmpdir =~ s,/+$,,; # Remove ending slash if any $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
# On some operating systems, there is a limit to the length of a
# UNIX domain socket's path far below PATH_MAX.
# Don't allow that to happen
if (check_socket_path_length("$opt_tmpdir/testsocket.sock")){
mtr_error("Socket path '$opt_tmpdir' too long, it would be ",
"truncated and thus not possible to use for connection to ",
"MySQL Server. Set a shorter with --tmpdir=<path> option");
}
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# fast option # fast option
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
...@@ -735,17 +744,6 @@ sub command_line_setup { ...@@ -735,17 +744,6 @@ sub command_line_setup {
$opt_user= "root"; # We want to do FLUSH xxx commands $opt_user= "root"; # We want to do FLUSH xxx commands
} }
# On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be
# considered different, so avoid the extra slash (/) in the socket
# paths.
my $sockdir = $opt_tmpdir;
$sockdir =~ s|/+$||;
# On some operating systems, there is a limit to the length of a
# UNIX domain socket's path far below PATH_MAX, so try to avoid long
# socket path names.
$sockdir = tempdir(CLEANUP => 0) if ( length($sockdir) >= 70 );
$path_testlog= "$opt_vardir/log/mysqltest.log"; $path_testlog= "$opt_vardir/log/mysqltest.log";
$path_current_testlog= "$opt_vardir/log/current_test"; $path_current_testlog= "$opt_vardir/log/current_test";
...@@ -1186,6 +1184,7 @@ sub environment_setup { ...@@ -1186,6 +1184,7 @@ sub environment_setup {
$ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir; $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
$ENV{'MYSQLTEST_VARDIR'}= $opt_vardir; $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
$ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'} || 3306; $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'master-port'} || 3306;
$ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir;
# ---------------------------------------------------- # ----------------------------------------------------
# Setup env for NDB # Setup env for NDB
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment