Skip to content

Commit 2a387b1

Browse files
Alex Vandivergitster
authored andcommitted
fsmonitor: read entirety of watchman output
In Perl, setting $/ sets the string that is used as the "record separator," which sets the boundary that the `<>` construct reads to. Setting `local $/ = 0666;` evaluates the octal, getting 438, and stringifies it. Thus, the later read from `<CHLD_OUT>` stops as soon as it encounters the string "438" in the watchman output, yielding invalid JSON; repositories containing filenames with SHA1 hashes are able to trip this easily. Set `$/` to undefined, thus slurping all output from watchman. Also close STDIN which is provided to watchman, to better guarantee that we cannot deadlock with watchman while both attempting to read. Signed-off-by: Alex Vandiver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dcdb71f commit 2a387b1

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

t/t7519/fsmonitor-watchman

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ launch_watchman();
5050

5151
sub launch_watchman {
5252

53-
# Set input record separator
54-
local $/ = 0666;
55-
5653
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j')
5754
or die "open2() failed: $!\n" .
5855
"Falling back to scanning...\n";
@@ -83,7 +80,8 @@ sub launch_watchman {
8380
close $fh;
8481

8582
print CHLD_IN $query;
86-
my $response = <CHLD_OUT>;
83+
close CHLD_IN;
84+
my $response = do {local $/; <CHLD_OUT>};
8785

8886
open ($fh, ">", ".git/watchman-response.json");
8987
print $fh $response;

templates/hooks--fsmonitor-watchman.sample

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ launch_watchman();
4949

5050
sub launch_watchman {
5151

52-
# Set input record separator
53-
local $/ = 0666;
54-
5552
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j')
5653
or die "open2() failed: $!\n" .
5754
"Falling back to scanning...\n";
@@ -78,7 +75,8 @@ sub launch_watchman {
7875
END
7976

8077
print CHLD_IN $query;
81-
my $response = <CHLD_OUT>;
78+
close CHLD_IN;
79+
my $response = do {local $/; <CHLD_OUT>};
8280

8381
die "Watchman: command returned no output.\n" .
8482
"Falling back to scanning...\n" if $response eq "";

0 commit comments

Comments
 (0)