[Crypt::SSLeay] OpenSSL 0.9.8b causes perl coredump

David Brownlee <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
For OpenSSL 0.9.8b SSLeay_add_all_algorithms() does not setup any
algorithms, wheras SSL_library_init() does. The net result was that
SSL_CTX_new() would return a NULL pointer causing a perl coredump
in such cases as:

     my $request  = HTTP::Request->new( "GET", 'https://<some_url>' );
     my $ua       = LWP::UserAgent->new;
     my $response = $ua->request($request);

The following patch fixes the error for this case, and tries to avoid
the perl crash in other cases: This is Crypt-SSLeay-0.51 against OpenSSL
0.9.8b under perl 5.8.8 on NetBSD/i386 4_BETA using gcc 4.1.2.

--- SSLeay.xs.orig	2003-05-28 07:55:02.000000000 +0100
+++ SSLeay.xs
@@ -107,7 +107,7 @@ SSL_CTX_new(packname, ssl_version)
          int rand_bytes_read;

  	if(!bNotFirstTime) {
-               SSLeay_add_all_algorithms();
+	       SSL_library_init();
                 SSL_load_error_strings();
                 ERR_load_crypto_strings();
  	       bNotFirstTime = 1;
@@ -130,10 +130,15 @@ SSL_CTX_new(packname, ssl_version)
  		/* v2 is the default */
  		ctx = SSL_CTX_new(SSLv2_client_method());
  	} 
-	SSL_CTX_set_options(ctx,SSL_OP_ALL|0);
+	if (ctx == 0)
+	   croak("SSL_CTX_new failed");
+	else
+	    {
+	    SSL_CTX_set_options(ctx,SSL_OP_ALL|0);

-	SSL_CTX_set_default_verify_paths(ctx);
-	SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
+	    SSL_CTX_set_default_verify_paths(ctx);
+	    SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
+	    }

  	RETVAL = ctx;


-- 
 			   David Brownlee -- [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.