From 75da5c2e16858487ff020be17639cdb6135d4cf8 Mon Sep 17 00:00:00 2001 From: Nikhil Mulley Date: Tue, 3 Jan 2012 00:35:30 +0530 Subject: [PATCH 1/2] Support for extended MySQL authentication for servers above 4.2 (includes 5.x) read the end of the packet stream correctly. -- Krisodb's patch. Details found at https://github.com/tsucchi/p5-Net-MySQL/issues/1 --- MySQL.pm | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/MySQL.pm b/MySQL.pm index 79a363e..034cd44 100644 --- a/MySQL.pm +++ b/MySQL.pm @@ -224,6 +224,8 @@ sub _get_server_information $i += 4; $self->{salt} = substr $message, $i, 8; # + $self->{saltold} = $self->{salt}; + # $i += 8+1; if (length $message >= $i + 1) { $i += 1; @@ -256,7 +258,19 @@ sub _request_authentication croak "Timeout of authentication"; } croak substr $auth_result, 7; - } + } elsif (ord(substr $auth_result, 4) == 254 ) { + $self->_send_password(); + $mysql->recv($auth_result, BUFFER_LENGTH, 0); + $self->_dump_packet($auth_result) if Net::MySQL->debug; + if ($self->_is_error($auth_result)) { + $mysql->close; + if (length $auth_result < 7) { + croak "Timeout of authentication"; + } + croak substr $auth_result, 7; + } + + } print "connect database\n" if Net::MySQL->debug; } @@ -281,6 +295,21 @@ sub _send_login_message } +sub _send_password +{ + my $self = shift; + my $mysql = $self->{socket}; + my $body = "\0\0\x03". + Net::MySQL::Password32->scramble( + $self->{password}, $self->{saltold}, $self->{client_capabilities} + ); + $body .= "\0"; + my $pw_message = chr(length($body)-3). $body; + $mysql->send($pw_message, 0); + $self->_dump_packet($pw_message) if Net::MySQL->debug; +} + + sub _execute_command { @@ -457,7 +486,7 @@ sub _has_next_packet my $self = shift; #substr($_[0], -1) ne "\xfe"; #$self->_dump_packet(substr($_[0], -5)); - return substr($_[0], -5, 1) ne "\xfe"; + return substr($[0], -5) ne "\xfe\0\0\x22\x00"; } From f658b9b3087f9fb9cb5d4772630e508abcb2c256 Mon Sep 17 00:00:00 2001 From: Nikhil Mulley Date: Tue, 3 Jan 2012 00:36:55 +0530 Subject: [PATCH 2/2] Read the end of the packet correctly for the record set query results. Net::MySQL hangs indefinitely waiting for another packet while the stream is already ended for the single query result set messages from the server. Details found at https://github.com/tsucchi/p5-Net-MySQL/issues/2 --- MySQL.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MySQL.pm b/MySQL.pm index 034cd44..c7b98cb 100644 --- a/MySQL.pm +++ b/MySQL.pm @@ -486,7 +486,7 @@ sub _has_next_packet my $self = shift; #substr($_[0], -1) ne "\xfe"; #$self->_dump_packet(substr($_[0], -5)); - return substr($[0], -5) ne "\xfe\0\0\x22\x00"; + return (substr($_[0],-5) ne "\xfe\0\0\x02\x00" and substr($_[0], -5) ne "\xfe\0\0\x22\x00"); }