If Bonjour disconnects but the user opens a contact window in the moment before the contact disappears from the list, it wass possible to attempt to open with a nil avInstanceName. Furthermore, if Bonjour disconnects, attempting to send a message to a still-open Bonjour chat could try to reference avInstanceName which would previously be nil after disconnect.
authorEvan Schoenberg
Sat Oct 31 12:31:33 2009 -0500 (2009-10-31)
changeset 2830c770142607e4
parent 2829 fa28661f40dd
child 2831 a736fd73ef9a
If Bonjour disconnects but the user opens a contact window in the moment before the contact disappears from the list, it wass possible to attempt to open with a nil avInstanceName. Furthermore, if Bonjour disconnects, attempting to send a message to a still-open Bonjour chat could try to reference avInstanceName which would previously be nil after disconnect.

There's no reason to be so aggressive with having avInstanceName only be set while logged in; it's a single string, and it doesn't generally change. We'll create it in init and destroy it in dealloc for AWEzvContactManager.

Fixes #11799 fully.
Plugins/Bonjour/libezv/Private Classes/AWEzvContactManager.m
Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m
     1.1 --- a/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManager.m	Sat Oct 31 12:18:11 2009 -0500
     1.2 +++ b/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManager.m	Sat Oct 31 12:31:33 2009 -0500
     1.3 @@ -42,6 +42,23 @@
     1.4  		contacts = [[NSMutableDictionary alloc] init];
     1.5  		client = newClient;
     1.6  		isConnected = NO;
     1.7 +		
     1.8 +		/* find username and computer name */
     1.9 +		CFStringRef consoleUser = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
    1.10 +		CFStringRef computerName = SCDynamicStoreCopyLocalHostName(NULL);
    1.11 +		if (!computerName) {
    1.12 +			/* computerName can return NULL if the computer name is not set or an error occurs */
    1.13 +			CFUUIDRef	uuid;
    1.14 +			
    1.15 +			uuid = CFUUIDCreate(NULL);
    1.16 +			computerName = CFUUIDCreateString(NULL, uuid);
    1.17 +			CFRelease(uuid);		
    1.18 +		}
    1.19 +		avInstanceName = [[NSString alloc] initWithFormat:@"%@@%@",
    1.20 +						  (consoleUser ? (NSString *)consoleUser : @""),
    1.21 +						  (computerName ? (NSString *)computerName : @"")];
    1.22 +		if (consoleUser) CFRelease(consoleUser);
    1.23 +		if (computerName) CFRelease(computerName);		
    1.24  	}
    1.25  
    1.26      return self;
    1.27 @@ -71,7 +88,9 @@
    1.28  - (void)dealloc {
    1.29  	/* AWEzvContactManagerListener adds an observer; remove it */
    1.30  	[[NSNotificationCenter defaultCenter] removeObserver:self];
    1.31 -	[userAnnounceData release];
    1.32 +
    1.33 +	[userAnnounceData release]; userAnnounceData = nil;
    1.34 +	[avInstanceName release]; avInstanceName = nil;
    1.35  
    1.36  	[super dealloc];
    1.37  }
     2.1 --- a/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m	Sat Oct 31 12:18:11 2009 -0500
     2.2 +++ b/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m	Sat Oct 31 12:31:33 2009 -0500
     2.3 @@ -159,22 +159,7 @@
     2.4  	[userAnnounceData setField:@"version" content:@"1"];
     2.5  
     2.6  	[self setStatus:[client status] withMessage:nil];
     2.7 -
     2.8 -	/* find username and computer name */
     2.9 -	CFStringRef consoleUser = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
    2.10 -	CFStringRef computerName = SCDynamicStoreCopyLocalHostName(NULL);
    2.11 -	if (!computerName) {
    2.12 -		/* computerName can return NULL if the computer name is not set or an error occurs */
    2.13 -		CFUUIDRef	uuid;
    2.14 -
    2.15 -		uuid = CFUUIDCreate(NULL);
    2.16 -		computerName = CFUUIDCreateString(NULL, uuid);
    2.17 -		CFRelease(uuid);		
    2.18 -	}
    2.19 -    avInstanceName = [NSString stringWithFormat:@"%@@%@", (consoleUser ? (NSString *)consoleUser : @""), (computerName ? (NSString *)computerName : @"")];
    2.20 -	if (consoleUser) CFRelease(consoleUser);
    2.21 -	if (computerName) CFRelease(computerName);
    2.22 -	[avInstanceName retain];
    2.23 +	
    2.24      /* register service with mDNSResponder */
    2.25  
    2.26  	DNSServiceRef servRef;
    2.27 @@ -226,8 +211,6 @@
    2.28  
    2.29  		avDNSReference = nil;
    2.30  		imageServiceRef = nil;
    2.31 -		
    2.32 -		[avInstanceName release]; avInstanceName = nil;
    2.33  	}
    2.34  
    2.35  	[self setConnected:NO];