Skip to content

Commit 9943a8b

Browse files
committed
Fix the way Sequel Pro was constructing command line arguments for SSH (#2273)
1 parent 8170ca8 commit 9943a8b

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Source/SPSSHTunnel.m

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ - (void)launchTask:(id) dummy
317317

318318
// Prepare to set up the arguments for the task
319319
taskArguments = [[NSMutableArray alloc] init];
320-
320+
#define TA(_name,_value) [taskArguments addObjectsFromArray:@[_name,_value]]
321+
321322
// Enable verbose mode for message parsing
322323
[taskArguments addObject:@"-v"];
323324

@@ -329,58 +330,58 @@ - (void)launchTask:(id) dummy
329330
if (connectionMuxingEnabled) {
330331

331332
// Enable automatic connection muxing/sharing, for faster connections
332-
[taskArguments addObject:@"-o ControlMaster=auto"];
333+
TA(@"-o",@"ControlMaster=auto");
333334

334335
// Set a custom control path to isolate connection sharing to Sequel Pro, to prevent picking up
335336
// existing masters without forwarding enabled and to isolate from interactive sessions. Use a short
336337
// hashed path to aid length limit issues.
337338
unsigned char hashedPathResult[16];
338339
NSString *pathString = [NSString stringWithFormat:@"%@@%@:%ld", sshLogin?sshLogin:@"", sshHost, (long)(sshPort?sshPort:0)];
339340
CC_MD5([pathString UTF8String], (unsigned int)strlen([pathString UTF8String]), hashedPathResult);
340-
[taskArguments addObject:[NSString stringWithFormat:@"-o ControlPath=%@/SPSSH-%@", [NSFileManager temporaryDirectory], [[[NSData dataWithBytes:hashedPathResult length:16] dataToHexString] substringToIndex:8]]];
341+
NSString *hashedString = [[[NSData dataWithBytes:hashedPathResult length:16] dataToHexString] substringToIndex:8];
342+
TA(@"-o",([NSString stringWithFormat:@"ControlPath=%@/SPSSH-%@", [NSFileManager temporaryDirectory], hashedString]));
341343
} else {
342344

343345
// Disable muxing if requested
344-
[taskArguments addObject:@"-S none"];
345-
[taskArguments addObject:@"-o ControlMaster=no"];
346+
TA(@"-S", @"none");
347+
TA(@"-o", @"ControlMaster=no");
346348
}
347349

348350
// If the port forwarding fails, exit - as this is the primary use case for the instance
349-
[taskArguments addObject:@"-o ExitOnForwardFailure=yes"];
351+
TA(@"-o",@"ExitOnForwardFailure=yes");
350352

351353
// Specify a connection timeout based on the preferences value
352-
[taskArguments addObject:[NSString stringWithFormat:@"-o ConnectTimeout=%ld", (long)connectionTimeout]];
354+
TA(@"-o",([NSString stringWithFormat:@"ConnectTimeout=%ld", (long)connectionTimeout]));
353355

354356
// Allow three password prompts
355-
[taskArguments addObject:@"-o NumberOfPasswordPrompts=3"];
357+
TA(@"-o",@"NumberOfPasswordPrompts=3");
356358

357359
// Specify an identity file if available
358360
if (identityFilePath) {
359-
[taskArguments addObject:@"-i"];
360-
[taskArguments addObject:identityFilePath];
361+
TA(@"-i", identityFilePath);
361362
}
362363

363364
// If keepalive is set in the preferences, use the same value for the SSH tunnel
364365
if (useKeepAlive && keepAliveInterval) {
365-
[taskArguments addObject:@"-o TCPKeepAlive=no"];
366-
[taskArguments addObject:[NSString stringWithFormat:@"-o ServerAliveInterval=%ld", (long)ceil(keepAliveInterval)]];
367-
[taskArguments addObject:@"-o ServerAliveCountMax=1"];
366+
TA(@"-o", @"TCPKeepAlive=no");
367+
TA(@"-o", ([NSString stringWithFormat:@"ServerAliveInterval=%ld", (long)ceil(keepAliveInterval)]));
368+
TA(@"-o", @"ServerAliveCountMax=1");
368369
}
369370

370371
// Specify the port, host, and authentication details
371372
if (sshPort) {
372-
[taskArguments addObject:[NSString stringWithFormat:@"-p %ld", (long)sshPort]];
373+
TA(@"-p", ([NSString stringWithFormat:@"%ld", (long)sshPort]));
373374
}
374375
if ([sshLogin length]) {
375376
[taskArguments addObject:[NSString stringWithFormat:@"%@@%@", sshLogin, sshHost]];
376377
} else {
377378
[taskArguments addObject:sshHost];
378379
}
379380
if (useHostFallback) {
380-
[taskArguments addObject:[NSString stringWithFormat:@"-L %ld:127.0.0.1:%ld", (long)localPort, (long)remotePort]];
381-
[taskArguments addObject:[NSString stringWithFormat:@"-L %ld:%@:%ld", (long)localPortFallback, remoteHost, (long)remotePort]];
381+
TA(@"-L",([NSString stringWithFormat:@"%ld:127.0.0.1:%ld", (long)localPort, (long)remotePort]));
382+
TA(@"-L",([NSString stringWithFormat:@"%ld:%@:%ld", (long)localPortFallback, remoteHost, (long)remotePort]));
382383
} else {
383-
[taskArguments addObject:[NSString stringWithFormat:@"-L %ld:%@:%ld", (long)localPort, remoteHost, (long)remotePort]];
384+
TA(@"-L", ([NSString stringWithFormat:@"%ld:%@:%ld", (long)localPort, remoteHost, (long)remotePort]));
384385
}
385386

386387
[task setArguments:taskArguments];
@@ -451,6 +452,7 @@ - (void)launchTask:(id) dummy
451452
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
452453

453454
SPClear(taskEnvironment);
455+
#undef TA
454456
SPClear(taskArguments);
455457

456458
[pool release];

0 commit comments

Comments
 (0)