Fix deadlock in stash levels

- use vertical tab character instead of "MAGIC" string to denote end of input
- check for terminator using pattern match instead of eq

Users are unable to provide special characters to Bash process so this should
be relatively safe. Pattern match succeeds even when `git stash` omits newline
while rendering commit subjects.

Fixes git-learning-game/oh-my-git#56
This commit is contained in:
mundifex 2021-03-25 22:51:56 -05:00 committed by Ben Donatelli
parent ec9b467cc6
commit c2a2f87f4c

View file

@ -34,12 +34,12 @@ while(true) {
STDOUT->flush(); STDOUT->flush();
$s = ""; $s = "";
$command = $s2 . "\necho MAGIC\n"; $command = $s2 . "\necho -e \"\\v\"\n";
print $in $command; print $in $command;
inner_while: while (true) { inner_while: while (true) {
$line = <$out>; $line = <$out>;
if ($line eq "MAGIC\n") { if ($line =~ s/\cK//) {
STDOUT->flush(); STDOUT->flush();
last inner_while; last inner_while;
} }