Skip to content

Commit 65a4ba2

Browse files
committed
fix: pass sanitized search to _do_search and guard $to_cache writes
Two bugs fixed: 1. _sanitize_search() result was never propagated back to %opts, so _do_search() received the original unsanitized user input. This bypassed newline removal, quote escaping, and character whitelisting before the search reached git grep. 2. In _run_child_git_grep(), lines 925-926 wrote to $to_cache unconditionally, but the filehandle is only initialized when $cache_file is set. This would crash the child process with "Can't use an undefined value as a filehandle" when caching is disabled. Also removes unused $gitdir variable in do_search().
1 parent a8e8eec commit 65a4ba2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/lib/GrepCpan/Grep.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,8 @@ sub do_search ( $self, %opts ) {
246246

247247
my $t0 = [Time::HiRes::gettimeofday];
248248

249-
my $gitdir = $self->git()->work_tree;
250-
251249
$search = _sanitize_search($search);
250+
$opts{search} = $search;
252251

253252
my $results = $self->_do_search(%opts);
254253

@@ -922,9 +921,11 @@ sub run_git_cmd_limit ( $self, %opts ) {
922921
last if ++$counter > $limit_bg_process;
923922
}
924923
$run->close;
925-
print {$to_cache}
926-
qq{\n}; # in case of the last line did not had a newline
927-
print {$to_cache} END_OF_FILE_MARKER() . qq{\n} if $cache_file;
924+
if ($cache_file) {
925+
print {$to_cache}
926+
qq{\n}; # in case of the last line did not had a newline
927+
print {$to_cache} END_OF_FILE_MARKER() . qq{\n};
928+
}
928929
print {$CW} END_OF_FILE_MARKER() . qq{\n} if $can_write_to_pipe;
929930
say "-- Request finished by kid: $counter lines - "
930931
. join( ' ', 'git', @$cmd );

0 commit comments

Comments
 (0)