From 771c3ff3aa15188771881e2447d491b359d4c5da Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 15 Apr 2010 00:14:48 +0000 Subject: - Add locking for SSH debug message processing - this addresses http://spbug.com/l/117 --- Source/SPSSHTunnel.h | 1 + Source/SPSSHTunnel.m | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPSSHTunnel.h b/Source/SPSSHTunnel.h index 27522d90..9230f7e1 100644 --- a/Source/SPSSHTunnel.h +++ b/Source/SPSSHTunnel.h @@ -52,6 +52,7 @@ NSString *keychainAccount; NSString *requestedPassphrase; NSMutableArray *debugMessages; + NSLock *debugMessagesLock; BOOL useHostFallback; BOOL requestedResponse; BOOL passwordInKeychain; diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m index dfeb2f16..eeef83d2 100644 --- a/Source/SPSSHTunnel.m +++ b/Source/SPSSHTunnel.m @@ -56,6 +56,7 @@ stateChangeSelector = nil; lastError = nil; debugMessages = [[NSMutableArray alloc] init]; + debugMessagesLock = [[NSLock alloc] init]; answerAvailableLock = [[NSLock alloc] init]; // Set up a connection for use by the tunnel process @@ -164,7 +165,10 @@ * by line endings. */ - (NSString *) debugMessages { - return [debugMessages componentsJoinedByString:@"\n"]; + [debugMessagesLock lock]; + NSString *debugMessagesString = [debugMessages componentsJoinedByString:@"\n"]; + [debugMessagesLock unlock]; + return debugMessagesString; } /* @@ -175,7 +179,9 @@ localPort = 0; if (connectionState != PROXY_STATE_IDLE) return; + [debugMessagesLock lock]; [debugMessages removeAllObjects]; + [debugMessagesLock unlock]; [NSThread detachNewThreadSelector:@selector(launchTask:) toTarget: self withObject: nil ]; } @@ -369,7 +375,8 @@ } /* - * Processes messages recieved from the SSH task + * Processes messages recieved from the SSH task. These may be received singly + * or several stuck together. */ - (void)standardErrorHandler:(NSNotification*)aNotification { @@ -385,7 +392,9 @@ enumerator = [messages objectEnumerator]; while (message = [[enumerator nextObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]) { if (![message length]) continue; + [debugMessagesLock lock]; [debugMessages addObject:[NSString stringWithString:message]]; + [debugMessagesLock unlock]; if ([message rangeOfString:@"Entering interactive session."].location != NSNotFound) { connectionState = PROXY_STATE_CONNECTED; @@ -625,6 +634,7 @@ [tunnelConnection invalidate]; [tunnelConnection release]; [debugMessages release]; + [debugMessagesLock release]; [answerAvailableLock tryLock]; [answerAvailableLock unlock]; [answerAvailableLock release]; -- cgit v1.2.3