KnowledgeBase → "Internal apreq error" in Apache 2 httpd error logs
After upgrading to APR libapreq2 v2.17, web pages generated by Perl scripts running in the modperl_2 v2.17 environment that attempt to utilize CGI parameters with the Apache2::Upload that don't contain any file upload data (or when malformed-or-missing HTTP headers are encountered), the process terminates and an "Internal apreq error" is recorded in the Apache httpd v2.4 error log (without indicating the problematic line number).The error is triggered by the final line in the following code:
use Apache2::Request; use Apache2::Upload; my $req = Apache2::Request->new($r); my $upload = $req->upload("cgi-parameter-name");
The short-term solution is to wrap the call to the $req->upload method in an eval{} block:
use Apache2::Request; use Apache2::Upload; my $req = Apache2::Request->new($r); my $upload; eval { $upload = $req->upload("cgi-parameter-name"); };
Although ignoring errors is normally a discouraged practice, in this case we're ignoring a situation where the user elected to not attach a file before submitting the HTML form (by way of the POST method with the enctype=multipart/form-data parameter).
Your code still needs to check whether a file was uploaded by testing whether the $upload variable is defined (consult the Apache2::Upload documentation for further information).
The better solution is to upgrade to libapreq2 v2.18, which can be accomplished with the following commands (which presumes aptitude on Debian Linux):
Only use the above method if libapreq-2.18 or newer is not provided by your Linux distribution's package manager (the package manager's version is normally preferred).# These instructions were written on Debian (Linux) to upgrade # libapreq-2.17 to libapreq-2.18 on 2024-Jan-11. # # Operating System: Debian 12.4 # Notes written by: Randolf Richardson # Author's eMail: <randolf@inter-corporate.com> # Web site address: https://www.inter-corporate.com/ # Web site address: https://www.randolf.ca/ # apt install subversion libextutils-xsbuilder-perl libtool-bin apache2-dev libapache2-mod-perl2-dev svn checkout http://svn.apache.org/repos/asf/httpd/apreq/trunk/ httpd-apreq-2 cd httpd-apreq-2 ./buildconf autoconf # Note: Use "whereis apxs" to confirm path of apxs then update # the --with-apache2-apxs option accordingly: # perl Makefile.PL --with-apache2-apxs=/usr/bin/apxs make make test # Note: Backup the following directories prior to installing: # /usr/include/apache2/ # /usr/include/apr-1.0/ # /usr/include/apreq2/ # /usr/lib/apache2/modules/ # # Also: If we don't remove the libapreq2-3 package, then the # Apache 2 httpd daemon will use the older version. (Do # not use "apt purge" to remove this module.) # systemctl stop apache2 apt remove libapreq2-3 make install a2enmod apreq2 systemctl start apache2