mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
small host lokup fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34629 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ca98447111
commit
c4f47d50c7
3 changed files with 26 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2012-01-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/GSSocketStream.m: fix possible nul pointer dereference.
|
||||||
|
* Source/NSHost.m: cache failed lookup by name so that repeated
|
||||||
|
lookups for a band host name do not cause repeated DNS queries.
|
||||||
|
|
||||||
2012-01-24 Richard Frith-Macdonald <rfm@gnu.org>
|
2012-01-24 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSURLRequest.m: be tolerant about missing URL on init.
|
* Source/NSURLRequest.m: be tolerant about missing URL on init.
|
||||||
|
|
|
@ -141,6 +141,10 @@ GSPrivateSockaddrSetup(NSString *machine, uint16_t port,
|
||||||
n = [machine UTF8String];
|
n = [machine UTF8String];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == n)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
if (0 == strchr(n, ':'))
|
if (0 == strchr(n, ':'))
|
||||||
{
|
{
|
||||||
struct sockaddr_in *addr = (struct sockaddr_in*)sin;
|
struct sockaddr_in *addr = (struct sockaddr_in*)sin;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#import "Foundation/NSArray.h"
|
#import "Foundation/NSArray.h"
|
||||||
#import "Foundation/NSDictionary.h"
|
#import "Foundation/NSDictionary.h"
|
||||||
#import "Foundation/NSEnumerator.h"
|
#import "Foundation/NSEnumerator.h"
|
||||||
|
#import "Foundation/NSNull.h"
|
||||||
#import "Foundation/NSSet.h"
|
#import "Foundation/NSSet.h"
|
||||||
#import "Foundation/NSCoder.h"
|
#import "Foundation/NSCoder.h"
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ static Class hostClass;
|
||||||
static NSRecursiveLock *_hostCacheLock = nil;
|
static NSRecursiveLock *_hostCacheLock = nil;
|
||||||
static BOOL _hostCacheEnabled = YES;
|
static BOOL _hostCacheEnabled = YES;
|
||||||
static NSMutableDictionary *_hostCache = nil;
|
static NSMutableDictionary *_hostCache = nil;
|
||||||
|
static id null = nil;
|
||||||
|
|
||||||
|
|
||||||
@interface NSHost (Private)
|
@interface NSHost (Private)
|
||||||
|
@ -75,7 +77,7 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
[s addObject: name];
|
[s addObject: name];
|
||||||
ASSIGNCOPY(_names, s);
|
ASSIGNCOPY(_names, s);
|
||||||
RELEASE(s);
|
RELEASE(s);
|
||||||
if (_hostCacheEnabled == YES)
|
if (YES == _hostCacheEnabled)
|
||||||
{
|
{
|
||||||
[_hostCache setObject: self forKey: name];
|
[_hostCache setObject: self forKey: name];
|
||||||
}
|
}
|
||||||
|
@ -91,7 +93,7 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
name = [name copy];
|
name = [name copy];
|
||||||
_names = [[NSSet alloc] initWithObjects: &name count: 1];
|
_names = [[NSSet alloc] initWithObjects: &name count: 1];
|
||||||
_addresses = RETAIN(_names);
|
_addresses = RETAIN(_names);
|
||||||
if (_hostCacheEnabled == YES)
|
if (YES == _hostCacheEnabled)
|
||||||
{
|
{
|
||||||
[_hostCache setObject: self forKey: name];
|
[_hostCache setObject: self forKey: name];
|
||||||
}
|
}
|
||||||
|
@ -202,7 +204,7 @@ static NSMutableDictionary *_hostCache = nil;
|
||||||
_addresses = [addresses copy];
|
_addresses = [addresses copy];
|
||||||
RELEASE(addresses);
|
RELEASE(addresses);
|
||||||
|
|
||||||
if (_hostCacheEnabled == YES)
|
if (YES == _hostCacheEnabled)
|
||||||
{
|
{
|
||||||
[_hostCache setObject: self forKey: name];
|
[_hostCache setObject: self forKey: name];
|
||||||
}
|
}
|
||||||
|
@ -261,6 +263,7 @@ myHostName()
|
||||||
if (self == [NSHost class])
|
if (self == [NSHost class])
|
||||||
{
|
{
|
||||||
hostClass = self;
|
hostClass = self;
|
||||||
|
null = [[NSNull null] retain];
|
||||||
_hostCacheLock = [[NSRecursiveLock alloc] init];
|
_hostCacheLock = [[NSRecursiveLock alloc] init];
|
||||||
_hostCache = [NSMutableDictionary new];
|
_hostCache = [NSMutableDictionary new];
|
||||||
}
|
}
|
||||||
|
@ -298,7 +301,7 @@ myHostName()
|
||||||
}
|
}
|
||||||
|
|
||||||
[_hostCacheLock lock];
|
[_hostCacheLock lock];
|
||||||
if (_hostCacheEnabled == YES)
|
if (YES == _hostCacheEnabled)
|
||||||
{
|
{
|
||||||
host = [_hostCache objectForKey: name];
|
host = [_hostCache objectForKey: name];
|
||||||
}
|
}
|
||||||
|
@ -332,6 +335,10 @@ myHostName()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (YES == _hostCacheEnabled)
|
||||||
|
{
|
||||||
|
[_hostCache setObject: null forKey: name];
|
||||||
|
}
|
||||||
NSLog(@"Host '%@' not found using 'gethostbyname()' - "
|
NSLog(@"Host '%@' not found using 'gethostbyname()' - "
|
||||||
@"perhaps the hostname is wrong or networking is not "
|
@"perhaps the hostname is wrong or networking is not "
|
||||||
@"set up on your machine", name);
|
@"set up on your machine", name);
|
||||||
|
@ -344,6 +351,10 @@ myHostName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ((id)host == null)
|
||||||
|
{
|
||||||
|
host = nil;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IF_NO_GC([[host retain] autorelease];)
|
IF_NO_GC([[host retain] autorelease];)
|
||||||
|
@ -406,7 +417,7 @@ myHostName()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[_hostCacheLock lock];
|
[_hostCacheLock lock];
|
||||||
if (_hostCacheEnabled == YES)
|
if (YES == _hostCacheEnabled)
|
||||||
{
|
{
|
||||||
host = [_hostCache objectForKey: address];
|
host = [_hostCache objectForKey: address];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue