From 81287473fc3b61e9ba74216e84ddf1c6d8215b31 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 18 Feb 2009 19:23:29 +0000 Subject: net.server: Fix some more potential nil handler accesses --- net/server.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'net/server.lua') diff --git a/net/server.lua b/net/server.lua index a5c8e24c..cea2ada3 100644 --- a/net/server.lua +++ b/net/server.lua @@ -369,7 +369,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end bufferqueuelen = bufferqueuelen + 1 bufferqueue[ bufferqueuelen ] = data - _writetimes[ handler ] = _writetimes[ handler ] or _currenttime + if handler then + _writetimes[ handler ] = _writetimes[ handler ] or _currenttime + end return true end handler.write = write @@ -470,7 +472,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) fatalerror = true disconnect( handler, err ) - handler.close( ) + _ = handler and handler.close( ) return false end end -- cgit v1.2.3 From c2b54ca16026643838440922fa966cea576f42d2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 27 Feb 2009 18:40:17 +0000 Subject: net.server: Some fixes for SSL/TLS handshake handling --- net/server.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'net/server.lua') diff --git a/net/server.lua b/net/server.lua index cea2ada3..aacadacc 100644 --- a/net/server.lua +++ b/net/server.lua @@ -480,16 +480,19 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport if sslctx then -- ssl? ssl = true local wrote + local read local handshake = coroutine_wrap( function( client ) -- create handshake coroutine local err for i = 1, 10 do -- 10 handshake attemps + _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen + _readlistlen = ( read and removesocket( _readlist, socket, _readlistlen ) ) or _readlistlen + read, wrote = nil, nil _, err = client:dohandshake( ) if not err then --out_put( "server.lua: ssl handshake done" ) - _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions handler.sendbuffer = _sendbuffer - --return dispatch( handler ) + -- return dispatch( handler ) return true else out_put( "server.lua: error during ssl handshake: ", err ) @@ -497,6 +500,10 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport _sendlistlen = _sendlistlen + 1 _sendlist[ _sendlistlen ] = client wrote = true + elseif err == "wantread" and not read then + _readlistlen = _readlistlen + 1 + _readlist [ _readlistlen ] = client + read = true end --coroutine_yield( handler, nil, err ) -- handshake not finished coroutine_yield( ) @@ -558,8 +565,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport handler.starttls = nil needtls = nil - handler.receivedata = handler.handshake - handler.dispatchdata = handler.handshake + handler.readbuffer = handshake + handler.sendbuffer = handshake handshake( socket ) -- do handshake end handler.readbuffer = _readbuffer -- cgit v1.2.3 From fffdba514a7f52494dbc6943da525171d2fd7104 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 1 Mar 2009 23:33:41 +0000 Subject: net.server: Don't retry if client closes socket during SSL handshaking --- net/server.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'net/server.lua') diff --git a/net/server.lua b/net/server.lua index aacadacc..e895f8aa 100644 --- a/net/server.lua +++ b/net/server.lua @@ -489,7 +489,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport read, wrote = nil, nil _, err = client:dohandshake( ) if not err then - --out_put( "server.lua: ssl handshake done" ) + out_put( "server.lua: ssl handshake done" ) handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions handler.sendbuffer = _sendbuffer -- return dispatch( handler ) @@ -504,12 +504,14 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport _readlistlen = _readlistlen + 1 _readlist [ _readlistlen ] = client read = true + else + break; end --coroutine_yield( handler, nil, err ) -- handshake not finished coroutine_yield( ) end end - disconnect( handler, "max handshake attemps exceeded" ) + disconnect( handler, "ssl handshake failed" ) handler.close( true ) -- forced disconnect return false -- handshake failed end -- cgit v1.2.3 From 0a2936fb0fef58e0937a86fa42e213bec51650f2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 2 Mar 2009 19:49:09 +0000 Subject: net.server: Fix to make sure we send a string to logging function --- net/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/server.lua') diff --git a/net/server.lua b/net/server.lua index e895f8aa..8d0d3b1a 100644 --- a/net/server.lua +++ b/net/server.lua @@ -438,7 +438,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport --out_put( "server.lua: read data '", buffer, "', error: ", err ) return dispatch( handler, buffer, err ) else -- connections was closed or fatal error - out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) + out_put( "server.lua: client ", ip, ":", tostring(clientport), " error: ", tostring(err) ) fatalerror = true disconnect( handler, err ) _ = handler and handler.close( ) -- cgit v1.2.3