Skip to content

Commit

Permalink
Avoid infinite loops when expanding variables
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Holzschuch committed Jan 9, 2018
1 parent 218dbeb commit 17bd4fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Blink/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>keyboard</string>
<key>NSSiriUsageDescription</key>
<string>storing commands</string>
<key>NSUserActivityTypes</key>
<array>
<string>com.blink.cmdline</string>
Expand All @@ -76,16 +80,18 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportsDocumentBrowser</key>
<true/>
Expand Down
1 change: 1 addition & 0 deletions Blink/SmartKeys/SmartKeysController.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ - (void)viewDidLoad
[self.allKeys addObjectsFromArray:AlternateKeys];
[self.allKeys addObjectsFromArray:CursorKeys];
[self.allKeys addObject:[[SmartKey alloc] initWithName:KbdEscKey symbol:UIKeyInputEscape]];
[super viewDidLoad];
}

- (void)invalidateTimer
Expand Down
1 change: 1 addition & 0 deletions Blink/TermController.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
- (void)terminate;
- (void)sigwinch;
- (BOOL)executeCommand:(NSMutableArray*)listArgv;
- (void)createPTY;

@end
8 changes: 5 additions & 3 deletions Sessions/MCPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ - (char **) makeargs:(NSMutableArray*) listArgv argc:(int*) argc
// Operations on individual arguments
NSString *argument = [listArgv objectAtIndex:i];
// 1b) expand environment variables, + "~" (not wildcards ? and *)
while ([argument containsString:@"$"]) {
bool stopParsing = false;
while (([argument containsString:@"$"]) && !stopParsing) {
// It has environment variables inside. Work on them one by one.
// position of first "$" sign:
NSRange r1 = [argument rangeOfString:@"$"];
Expand All @@ -152,7 +153,7 @@ - (char **) makeargs:(NSMutableArray*) listArgv argc:(int*) argc
NSString* replacement_string = [NSString stringWithCString:variable encoding:NSASCIIStringEncoding];
variable_string = [[NSString stringWithCString:"$" encoding:NSASCIIStringEncoding] stringByAppendingString:variable_string];
argument = [argument stringByReplacingOccurrencesOfString:variable_string withString:replacement_string];
}
} else stopParsing = true;
}
// Bash spec: only convert "~" if: at the beginning of argument, after a ":" or the first "="
// ("=" scenario for export, but we use setenv, so no "=").
Expand Down Expand Up @@ -325,6 +326,7 @@ - (bool)executeCommand:(int)argc argv:(char **)argv {
free(cmd);
stdout = saved_out;
stderr = saved_err;
stdin = _stream.in;
}
}
return false;
Expand All @@ -341,7 +343,7 @@ - (BOOL)executeCommand:(NSMutableArray*) listArgv {
}

// This is a superset of all commands available. We check at runtime whether they are actually available (using ios_executable)
char* commandList[] = {"ls", "touch", "rm", "cp", "ln", "link", "mv", "mkdir", "chown", "chgrp", "chflags", "chmod", "du", "df", "chksum", "sum", "stat", "readlink", "compress", "uncompress", "gzip", "gunzip", "tar", "printenv", "pwd", "uname", "date", "env", "id", "groups", "whoami", "uptime", "w", "cat", "wc", "grep", "egrep", "fgrep", "curl", "python", "lua", "luac", "amstex", "cslatex", "csplain", "eplain", "etex", "jadetex", "latex", "mex", "mllatex", "mltex", "pdflatex", "pdftex", "pdfcslatex", "pdfcstex", "pdfcsplain", "pdfetex", "pdfjadetex", "pdfmex", "pdfxmltex", "texsis", "utf8mex", "xmltex", "lualatex", "luatex", "texlua", "texluac", "dviluatex", "dvilualatex", "bibtex", "setenv", "unsetenv", "cd",
char* commandList[] = {"ls", "touch", "rm", "cp", "ln", "link", "mv", "mkdir", "chown", "chgrp", "chflags", "chmod", "du", "df", "chksum", "sum", "stat", "readlink", "compress", "uncompress", "gzip", "gunzip", "tar", "printenv", "pwd", "uname", "date", "env", "id", "groups", "whoami", "uptime", "w", "cat", "wc", "grep", "egrep", "fgrep", "curl", "python", "lua", "luac", "amstex", "cslatex", "csplain", "eplain", "etex", "jadetex", "latex", "mex", "mllatex", "mltex", "pdflatex", "pdftex", "pdfcslatex", "pdfcstex", "pdfcsplain", "pdfetex", "pdfjadetex", "pdfmex", "pdfxmltex", "texsis", "utf8mex", "xmltex", "lualatex", "luatex", "texlua", "texluac", "dviluatex", "dvilualatex", "bibtex", "setenv", "unsetenv", "cd",
NULL}; // must end with NULL pointer

// Commands defined outside of ios_executable:
Expand Down

0 comments on commit 17bd4fc

Please sign in to comment.