diff options
author | Alex Vandiver <alexmv@dropbox.com> | 2017-10-03 23:27:46 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-10-04 18:58:53 +0900 |
commit | 2a387b17c5bc5e0872bed352a41a2b312ea86f9b (patch) | |
tree | 28e39bf1dc1bbff4003023509b0222b86b4c6f2c /templates/hooks--fsmonitor-watchman.sample | |
parent | dcdb71f1599734ae46870d3eca11e2093bbd7520 (diff) | |
download | git-2a387b17c5bc5e0872bed352a41a2b312ea86f9b.tar.gz |
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 <alexmv@dropbox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'templates/hooks--fsmonitor-watchman.sample')
-rwxr-xr-x | templates/hooks--fsmonitor-watchman.sample | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/templates/hooks--fsmonitor-watchman.sample b/templates/hooks--fsmonitor-watchman.sample index c68038ef00..9eba8a7409 100755 --- a/templates/hooks--fsmonitor-watchman.sample +++ b/templates/hooks--fsmonitor-watchman.sample @@ -49,9 +49,6 @@ launch_watchman(); sub launch_watchman { - # Set input record separator - local $/ = 0666; - my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j') or die "open2() failed: $!\n" . "Falling back to scanning...\n"; @@ -78,7 +75,8 @@ sub launch_watchman { END print CHLD_IN $query; - my $response = <CHLD_OUT>; + close CHLD_IN; + my $response = do {local $/; <CHLD_OUT>}; die "Watchman: command returned no output.\n" . "Falling back to scanning...\n" if $response eq ""; |