Fixes for obscure problems with ssl connection when networks are extremely

slow or system is overloaded/blocked in some way.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21474 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-07-14 19:53:17 +00:00
parent ce3770a02c
commit d75f98906c
2 changed files with 41 additions and 4 deletions

View file

@ -1,3 +1,12 @@
2005-07-14 Richard Frith-Macdonald <rfm@gnu.org>
* SSL/GSSSLHandle.m: Retains self when running runloop to allow
ssl connect and accept operations. If the connect/accept takes
a long time, the caller might give up and release the handle,
causing resources to be freed and the ssl operation to crash.
Retaining self (and noticing when a disconnect has taken place)
prevents that.
2005-07-13 Nicola Pero <n.pero@mi.flashnet.it> 2005-07-13 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSBundle.m: When building paths inside framework * Source/NSBundle.m: When building paths inside framework

View file

@ -206,12 +206,17 @@ sslError(int err, int e)
{ {
ssl = SSL_new(ctx); ssl = SSL_new(ctx);
} }
RETAIN(self); // Don't get destroyed during runloop
loop = [NSRunLoop currentRunLoop]; loop = [NSRunLoop currentRunLoop];
ret = SSL_set_fd(ssl, descriptor); ret = SSL_set_fd(ssl, descriptor);
if (ret == 1) if (ret == 1)
{ {
[loop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]]; [loop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
if (ssl == 0)
{
RELEASE(self);
return NO;
}
ret = SSL_accept(ssl); ret = SSL_accept(ssl);
} }
if (ret != 1) if (ret != 1)
@ -222,7 +227,7 @@ sslError(int err, int e)
NSTimeInterval last = 0.0; NSTimeInterval last = 0.0;
NSTimeInterval limit = 0.1; NSTimeInterval limit = 0.1;
final = [[NSDate alloc] initWithTimeIntervalSinceNow: 20.0]; final = [[NSDate alloc] initWithTimeIntervalSinceNow: 30.0];
when = [NSDate alloc]; when = [NSDate alloc];
err = SSL_get_error(ssl, ret); err = SSL_get_error(ssl, ret);
@ -235,6 +240,13 @@ sslError(int err, int e)
last = tmp; last = tmp;
when = [when initWithTimeIntervalSinceNow: limit]; when = [when initWithTimeIntervalSinceNow: limit];
[loop runUntilDate: when]; [loop runUntilDate: when];
if (ssl == 0)
{
RELEASE(when);
RELEASE(final);
RELEASE(self);
return NO;
}
ret = SSL_accept(ssl); ret = SSL_accept(ssl);
if (ret != 1) if (ret != 1)
{ {
@ -255,10 +267,12 @@ sslError(int err, int e)
NSLog(@"unable to accept SSL connection from %@:%@ - %@", NSLog(@"unable to accept SSL connection from %@:%@ - %@",
address, service, str); address, service, str);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
RELEASE(self);
return NO; return NO;
} }
} }
connected = YES; connected = YES;
RELEASE(self);
return YES; return YES;
} }
@ -289,12 +303,17 @@ ERR_print_errors_fp(stderr);
{ {
ssl = SSL_new(ctx); ssl = SSL_new(ctx);
} }
RETAIN(self); // Don't get destroyed during runloop
loop = [NSRunLoop currentRunLoop]; loop = [NSRunLoop currentRunLoop];
ret = SSL_set_fd(ssl, descriptor); ret = SSL_set_fd(ssl, descriptor);
if (ret == 1) if (ret == 1)
{ {
[loop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]]; [loop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
if (ssl == 0)
{
RELEASE(self);
return NO;
}
ret = SSL_connect(ssl); ret = SSL_connect(ssl);
} }
if (ret != 1) if (ret != 1)
@ -305,7 +324,7 @@ ERR_print_errors_fp(stderr);
NSTimeInterval last = 0.0; NSTimeInterval last = 0.0;
NSTimeInterval limit = 0.1; NSTimeInterval limit = 0.1;
final = [[NSDate alloc] initWithTimeIntervalSinceNow: 20.0]; final = [[NSDate alloc] initWithTimeIntervalSinceNow: 30.0];
when = [NSDate alloc]; when = [NSDate alloc];
err = SSL_get_error(ssl, ret); err = SSL_get_error(ssl, ret);
@ -318,6 +337,13 @@ ERR_print_errors_fp(stderr);
last = tmp; last = tmp;
when = [when initWithTimeIntervalSinceNow: limit]; when = [when initWithTimeIntervalSinceNow: limit];
[loop runUntilDate: when]; [loop runUntilDate: when];
if (ssl == 0)
{
RELEASE(when);
RELEASE(final);
RELEASE(self);
return NO;
}
ret = SSL_connect(ssl); ret = SSL_connect(ssl);
if (ret != 1) if (ret != 1)
{ {
@ -338,10 +364,12 @@ ERR_print_errors_fp(stderr);
NSLog(@"unable to make SSL connection to %@:%@ - %@", NSLog(@"unable to make SSL connection to %@:%@ - %@",
address, service, str); address, service, str);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
RELEASE(self);
return NO; return NO;
} }
} }
connected = YES; connected = YES;
RELEASE(self);
return YES; return YES;
} }