Further reduce the chance of an NRE in WebConnection, ref: 55f400b6446024adef5dcc8cc6...
authorSebastien Pouliot <sebastien@xamarin.com>
Tue, 5 Nov 2013 21:52:08 +0000 (16:52 -0500)
committerSebastien Pouliot <sebastien@xamarin.com>
Tue, 5 Nov 2013 21:52:19 +0000 (16:52 -0500)
mcs/class/System/System.Net/WebConnection.cs

index 2033fe9b79f238fbce95963314eec2f480eeacff..7f65751c679f25aab1a931ebcde6ab20ca9e7b72 100644 (file)
@@ -613,16 +613,16 @@ namespace System.Net
                        return (statusCode >= 200 && statusCode != 204 && statusCode != 304);
                }
 
-               internal void GetCertificates () 
+               internal void GetCertificates (Stream stream
                {
                        // here the SSL negotiation have been done
 #if SECURITY_DEP && MONOTOUCH
-                       HttpsClientStream s = (nstream as HttpsClientStream);
+                       HttpsClientStream s = (stream as HttpsClientStream);
                        X509Certificate client = s.SelectedClientCertificate;
                        X509Certificate server = s.ServerCertificate;
 #else
-                       X509Certificate client = (X509Certificate) piClient.GetValue (nstream, null);
-                       X509Certificate server = (X509Certificate) piServer.GetValue (nstream, null);
+                       X509Certificate client = (X509Certificate) piClient.GetValue (stream, null);
+                       X509Certificate server = (X509Certificate) piServer.GetValue (stream, null);
 #endif
                        sPoint.SetCertificates (client, server);
                        certsAvailable = (server != null);
@@ -1144,16 +1144,16 @@ namespace System.Net
                        lock (this) {
                                if (Data.request != request)
                                        throw new ObjectDisposedException (typeof (NetworkStream).FullName);
-                               if (nstream == null)
-                                       return false;
                                s = nstream;
+                               if (s == null)
+                                       return false;
                        }
 
                        try {
                                s.Write (buffer, offset, size);
                                // here SSL handshake should have been done
                                if (ssl && !certsAvailable)
-                                       GetCertificates ();
+                                       GetCertificates (s);
                        } catch (Exception e) {
                                err_msg = e.Message;
                                WebExceptionStatus wes = WebExceptionStatus.SendFailure;