beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 140 forks source link

"use of uninitialised value" error in ack #639

Closed DMaendlen closed 5 years ago

DMaendlen commented 7 years ago

Hi,

if I run ack -l on my whole system, I get the error Use of uninitialized value $content in pattern match (m//) at /usr/bin/ack line 837.

I think this should be remedied.

The bug was within ack 2.14, running Perl 5.24.1 on an up-to-date gentoo.

Thank you for your time

petdance commented 7 years ago

Can you please show the exact command line you executed?

petdance commented 7 years ago

From earlier email from @DMaendlen, the specifics of what line 837 is in his ack.

head -n 850 /usr/bin/ack | tail -n 20
           # XXX read in chunks
           # XXX only do this for certain file sizes?
           my $content = do {
               local $/;
               <$fh>;
           };
           $has_match = $content =~ /$re/og; # <- this is line 837
       }
       close $fh;
   }

   return $has_match;
}

sub count_matches_in_resource {
   my ( $resource, $opt ) = @_;

   my $nmatches = 0;
   my $fh = $resource->open();
   if ( !$fh ) {
petdance commented 7 years ago

Also, FYI, you can use ack's --lines option to do that: ack --lines=830-850 /usr/bin/ack

DMaendlen commented 7 years ago

Very nice, thank you for this.

The exact command was

for i in $(ack -l 'damait06' /); do sed -i 's/damait06/dmaendlen/g' $i; done

Goal was to replace my old username from uni.

petdance commented 7 years ago

What happens if you run ack -l 'damait06' not inside the for loop?

DMaendlen commented 7 years ago

Exactly the same. No output for a while, then "uninitialized value ..."

petdance commented 7 years ago

Can you narrow it down to a specific starting directory?

I have nothing to go off of here. I need you to do some narrowing down.

DMaendlen commented 7 years ago

When I did for i in /*; do echo "$i\n\n"; ack -l damait06 $i; done I was able to narrow it down to /proc

A further test with just ack -l damait06 /proc confirmed this.

A new test with for i in /proc/*; do echo "$i\n"; ack -l damait06 $i;done showed, that the problem was in the numeric directories (e. g. /proc/1) of /proc

Not sure if that helps.

petdance commented 7 years ago

What if you try to grep through /proc?

DMaendlen commented 7 years ago

grep -r 'damait06' /proc results in grep: /proc/sys/fs/binfmt_misc/register: Invalid argument grep: /proc/sys/net/ipv4/route/flush: Permission denied grep: /proc/sys/net/ipv6/conf/all/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/default/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/eth0/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/lo/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/sit0/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/wlan0/stable_secret: Input/output error grep: /proc/sys/net/ipv6/route/flush: Permission denied grep: /proc/sys/vm/compact_memory: Permission denied grep: /proc/kmsg: Resource temporarily unavailable

But obviously has no problems with e. g. /proc/1

petdance commented 5 years ago

There will be no more releases of ack 2. If this is still a problem with ack 3, please make an issue there: https://github.com/beyondgrep/ack3.