Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls: avoid invalid closedir() #801

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bin/ls
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ sub DirEntries {
my @Entries = (); # entries in original order
my $Name = ""; # entry name

if (!opendir($dh, $_[0]) || exists($Options{'d'})) {
if (exists $Options{'d'} || ! -d $_[0]) {
if (-e $_[0]) {
closedir($dh) if (defined($dh));
push(@Entries, $_[0]);
$Attributes{$_[0]} = stat($_[0]);
push(@Entries, \%Attributes);
Expand All @@ -161,6 +160,10 @@ sub DirEntries {
warn "$Program: can't access '$_[0]': $!\n";
return ();
}
unless (opendir $dh, $_[0]) {
warn "$Program: failed to open directory '$_[0]': $!\n";
return ();
}
while ($Name = readdir($dh)) {
next if (!exists($Options->{'a'}) &&
$Name =~ m/^\./o);
Expand Down
Loading