skip to Main Content

I just installed Centos 8 on my server to migrate everything from Centos 7 to Centos 8. I make use a many custom written Perl CGI scripts that is used with the web server (Apache). These scripts have many .pm modules that they use. To include the modules from the .cgi script files ‘use’ is being used. For example:

/cgi-bin/somescript.cgi

#!/usr/bin/perl
use some_module;

In the example above some_module.pm is located inside /cgi-bin but when I try to run http://192.168.0.1/cgi-bin/somescript.cgi the following error occurs:
Can’t locate some_module.pm in @INC

This used to work flawlessly in Centos 7 but not in Centos 8. How would I go about to get Perl to look inside the current directory for the modules like it used to in earlier versions of Centos when the .cgi script files are executed?

2

Answers


  1. As @choroba indicated in their comment, . is no longer in the default list of paths in @INC. You can add a library path with use lib:

    use lib '/cgi-bin';

    or

    use lib '/var/www/cgi-bin';

    (whichever more accurately reflects your libraries’ location.)

    Login or Signup to reply.
  2. Centos 7 includes Perl 5.16.3. Centos 8 includes Perl 5.26.3. That’s a difference of five major versions (5.18, 5.20, 5.22, 5.24 and 5.26). Before making such a big leap in versions, it is wise to read the relevant perldelta manual pages.

    In perl5260delta, you will find this:

    Removal of the current directory (".") from @INC

    The perl binary includes a default set of paths in @INC. Historically it has also included the current directory (".") as the final entry, unless run with taint mode enabled (perl -T). While convenient, this has security implications: for example, where a script attempts to load an optional module when its current directory is untrusted (such as /tmp), it could load and execute code from under that directory.

    Starting with v5.26, "." is always removed by default, not just under tainting. This has major implications for installing modules and executing scripts.

    So by updating to this version, you have broken your code.

    The simple (but ill-advised) fix that brings back the previous behaviour is to add this near the top of your file (before it tries to load the libraries):

    use lib '.';
    

    However, this isn’t recommended as it breaks when your code is not run from the directory containing your code. The better fix has always been to add a library path that is relative to the directory containing the main program. That might look like this:

    use FindBin '$RealBin';
    use lib $RealBin;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search