• Hi,

    We’re encountering a fatal error in the Wordfence plugin related to the readdir() function. Here’s the full error message:

    PHP Fatal error:  Uncaught TypeError: readdir(): Argument #1 ($dir_handle) must be of type resource or null, false given in /wp-content/plugins/wordfence/lib/wfDirectoryIterator.php:51

    After some debugging, we found that the issue occurs in the scan() method of the wfDirectoryIterator class:

    protected function scan($dir) {
    $dir = rtrim($dir, DIRECTORY_SEPARATOR);
    print_r($dir); // it returns an empty string ('').
    $handle = opendir($dir);
    $file_count = 0;
    while ($file = readdir($handle)) {
    ...
    }
    }

    In our case, the $dir variable is '/'. When passed to rtrim('/', DIRECTORY_SEPARATOR), it returns an empty string (''). As a result, opendir('') fails and returns false, which leads to the readdir() error since it’s expecting a valid directory handle.

    Could you please advise on how this should be handled, or whether a fix can be made to ensure the root directory '/' is preserved correctly?

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support wfpeter

    (@wfpeter)

    Hi @addslashes, thank-you for your detailed look into what’s happening.

    Could you please send Diagnostics so our team can see more about how WordPress is set up on your server? It will just help clarify if there’s an issue with the configuration of the path itself, or we need to address something in the plugin. Feel free to mention here any other notable factors in how the server is configured, such as whether symlinks are being used, etc.

    You can send a diagnostic to wftest @ wordfence . com directly from the top of the Wordfence > Tools > Diagnostics page. Then click on “Send Report by Email”. Please add your forum username where indicated and respond here again after you have sent it.

    NOTE: It should look as follows – Screenshot of Tools > Diagnostic > Send by Email

    Many thanks,
    Peter.

    Thread Starter addslashes

    (@addslashes)

    Hi @wfpeter

    I have just sent it.
    Thank you

    Plugin Support wfpeter

    (@wfpeter)

    Thanks for sending that over @addslashes!

    We’ve seen this host come up a couple of times before configuring ABSPATH to // instead of something like /home/user/public_html/my-wordpress/. I have logged a development request with the team so that the plugin could work around it although it’s not the regular way to configure a WordPress site, so it’s not a common problem. The quickest way for a resolution would be for your host to set ABSPATH to the root directory of your WordPress installation.

    The host may be running a container setup, where WP core files are actually in / although two slashes showing up in the ABSPATH may still be a misconfiguration so it’s worth speaking with them.

    You may need to disable the activity report to avoid the error until the path can be altered by your host, or we are able to issue an update.

    Thanks,
    Peter.

    • This reply was modified 1 year, 1 month ago by wfpeter. Reason: Added information about possibly running the WordPress site in a container
    Thread Starter addslashes

    (@addslashes)

    Thank you for your help 🙂

    Plugin Support wfpeter

    (@wfpeter)

    No worries @addslashes, please let us know if you hear more from them around how WordPress is configured on their platform and if they were able to resolve the problem for you.

    Peter.

    Thread Starter addslashes

    (@addslashes)

    Sure, I’ll let you know as soon as I hear anything from them.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Fatal error in wfDirectoryIterator.php: readdir(): false given’ is closed to new replies.