Security Advisories (1)
CVE-2025-40909 (2025-05-30)

Perl threads have a working directory race condition where file operations may target unintended paths. If a directory handle is open at thread creation, the process-wide current working directory is temporarily changed in order to clone that handle for the new thread, which is visible from any third (or more) thread already running. This may lead to unintended operations such as loading code or accessing files from unexpected locations, which a local attacker may be able to exploit. The bug was introduced in commit 11a11ecf4bea72b17d250cfb43c897be1341861e and released in Perl version 5.13.6

NAME

DirHandle - (obsolete) supply object methods for directory handles

SYNOPSIS

# recommended approach since Perl 5.6: do not use DirHandle
if (opendir my $d, '.') {
    while (readdir $d) { something($_); }
    rewind $d;
    while (readdir $d) { something_else($_); }
}

# how you would use this module if you were going to
use DirHandle;
if (my $d = DirHandle->new(".")) {
    while (defined($_ = $d->read)) { something($_); }
    $d->rewind;
    while (defined($_ = $d->read)) { something_else($_); }
}

DESCRIPTION

There is no reason to use this module nowadays.

The DirHandle method provide an alternative interface to the opendir(), closedir(), readdir(), and rewinddir() functions.

Up to Perl 5.5, opendir() could not autovivify a directory handle from undef, so using a lexical handle required using a function from Symbol to create an anonymous glob, which took a separate step. DirHandle encapsulates this, which allowed cleaner code than opendir(). Since Perl 5.6, opendir() alone has been all you need for lexical handles.