> When I run a CGI program as such, hostname works.  When I run it under
> Aapche::Registry, it fails.   Can anyone understand why?  Sorry, I am
> new to all this.
> 
>  [error] Cannot get host name of local machine at
> /home/httpd/dbi/frame_control.cgi line 13
> 
> use Sys::Hostname;
> 
> my $hostname = hostname();
> my $URL = "http://$hostname/dbi/";

Well the package does lots of evals but never uses the $@, that's why you
are clueless of why the whole thing doesn't work. So first lets replace:

    || Carp::croak "Cannot get host name of local machine:";
with
    || Carp::croak "Cannot get host name of local machine: $@";
in Sys/Hostaname.pm

now when the call fails we see the following error message:
[Thu Nov  4 09:12:34 1999] [error] Cannot get host name of local machine:
Insecure $ENV{PATH} while running with -T switch at
/usr/lib/perl5/5.00503/Sys/Hostname.pm line 109.

Well that's too easy... all you need is to secure the $ENV{PATH} variable,
since the module isn't taint mode aware (referer to perlsec manpage
for more info). The following fix makes it work:

$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
use Sys::Hostname;

my $hostname = hostname();
my $URL = "http://$hostname/dbi/";
print $URL;

I understand that it's just a snippet that represent the problem, but just
in case the proper style should ensure that the variable is initialized,
so:

my $hostname = hostname() || '';

I apologize, if I stress on something you know already :)


_______________________________________________________________________
Stas Bekman  mailto:[EMAIL PROTECTED]    www.singlesheaven.com/stas  
Perl,CGI,Apache,Linux,Web,Java,PC at  www.singlesheaven.com/stas/TULARC
www.apache.org  & www.perl.com  == www.modperl.com  ||  perl.apache.org
single o-> + single o-+ = singlesheaven    http://www.singlesheaven.com

Reply via email to