From 2a387b17c5bc5e0872bed352a41a2b312ea86f9b Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 3 Oct 2017 23:27:46 -0700 Subject: 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 `` 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 Signed-off-by: Junio C Hamano --- t/t7519/fsmonitor-watchman | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 't') diff --git a/t/t7519/fsmonitor-watchman b/t/t7519/fsmonitor-watchman index cca3d71e90..51330f8b3d 100755 --- a/t/t7519/fsmonitor-watchman +++ b/t/t7519/fsmonitor-watchman @@ -50,9 +50,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"; @@ -83,7 +80,8 @@ sub launch_watchman { close $fh; print CHLD_IN $query; - my $response = ; + close CHLD_IN; + my $response = do {local $/; }; open ($fh, ">", ".git/watchman-response.json"); print $fh $response; -- cgit v1.2.3