Bug#35735 mysql-test-run.pl creates tmpdir for socket path longer than 70
- Additional patch with improved protection by putting it all inside an "eval" - Calling 'hostpath' on a truncated socket may also croak. - Remove the need to create any directory parts of "path" inside the function.
This commit is contained in:
parent
bf33a3fa89
commit
c2a4f3901b
@ -100,47 +100,43 @@ sub posix_path {
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use File::Temp qw /tempdir/;
|
||||||
|
|
||||||
sub check_socket_path_length {
|
sub check_socket_path_length {
|
||||||
my ($path)= @_;
|
my ($path)= @_;
|
||||||
my $truncated= 0;
|
|
||||||
|
|
||||||
return 0 if IS_WINDOWS;
|
return 0 if IS_WINDOWS;
|
||||||
|
|
||||||
require IO::Socket::UNIX;
|
require IO::Socket::UNIX;
|
||||||
|
|
||||||
|
my $truncated= 1; # Be negative
|
||||||
|
|
||||||
|
# Create a tempfile name with same length as "path"
|
||||||
|
my $tmpdir = tempdir( CLEANUP => 0);
|
||||||
|
my $len = length($path) - length($tmpdir);
|
||||||
|
my $testfile = $tmpdir . "x" x ($len > 0 ? $len : 1);
|
||||||
my $sock;
|
my $sock;
|
||||||
eval {
|
eval {
|
||||||
# Create the directories where the
|
|
||||||
# socket till be created
|
|
||||||
mkpath(dirname($path));
|
|
||||||
|
|
||||||
$sock= new IO::Socket::UNIX
|
$sock= new IO::Socket::UNIX
|
||||||
(
|
(
|
||||||
Local => $path,
|
Local => $testfile,
|
||||||
Listen => 1,
|
Listen => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
die "Could not create UNIX domain socket: $!"
|
||||||
|
unless defined $sock;
|
||||||
|
|
||||||
|
die "UNIX domain socket patch was truncated"
|
||||||
|
unless ($testfile eq $sock->hostpath());
|
||||||
|
|
||||||
|
$truncated= 0; # Yes, it worked!
|
||||||
|
|
||||||
};
|
};
|
||||||
if ($@)
|
#print "check_socket_path_length, failed: ", $@, '\n' if ($@);
|
||||||
{
|
|
||||||
print $@, '\n';
|
$sock= undef; # Close socket
|
||||||
return 2;
|
unlink($testfile); # Remove the physical file
|
||||||
}
|
rmdir($tmpdir); # Remove the tempdir
|
||||||
if (!defined $sock){
|
|
||||||
#print "Could not create UNIX domain socket: $!\n";
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
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; # Close socket
|
|
||||||
unlink($path); # Remove the physical file
|
|
||||||
return $truncated;
|
return $truncated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user