| Author |
Unitialised value in String
|
|
| Richard Luckhurst 2006-10-24, 3:56 am |
| Hi All
I am a perl newbie.
I have a small perl script that is actually a cgi-bin script. I am told that
until a recent server change over it ran fine however now it produces no output.
I have tried running it from a command line and redirecting the input it would
have received as a cgi-bin script from a text file. I am getting a couple of
"Use of uninitialized value in concatenation (.) or string" errors and I can not
see why.
The script is as follows
#!/usr/bin/perl
#
# log-errors cgi-bin script to display the last 2000 lines of an error log.
# domain is the domain name of the virtual apache server
#
require '/www/server/cgi-bin/cgi-lib.pl';
&ReadParse(*in);
$domain = $in{'domain'};
print "Content-type: text/html\n\n";
print "<html><head><title>Exodus Web Server Log</title></head>\n";
print "<body link=\"blue\" vlink=\"blue\">\n";
print "<font size=\"4\"><b>Last 2000 Lines of the Error log for: $domain</b></font><br>\n";
print "<font size=\"1\"><br></font>Go to <a href=\"#bottom\"><i>End of log</i></a><br><br>\n";
$tail = `tail -n2000 /var/log/httpd/$domain-error_log 2>/dev/null | tac`;
$tail =~ s/</<\;/g;
$tail =~ s/>/>\;/g;
print "<pre>$tail<\/pre>\n";
print "<a name=\"bottom\"></a>";
print "<br><b>End of log</b><br>\n";
print "</body></html>\n";
exit 0;
When I run the script from the command line with the command
perl -w log-err* < test.txt
Where test.txt contains domain=www.resmaster.com
I get the following output
Content-type: text/html
<html><head><title>Exodus Web Server Log</title></head>
<body link="blue" vlink="blue">
Use of uninitialized value in concatenation (.) or string at log-errors line 10.
<font size="4"><b>Last 2000 Lines of the Error log for: </b></font><br>
<font size="1"><br></font>Go to <a href="#bottom"><i>End of log</i></a><br><br>
Use of uninitialized value in concatenation (.) or string at log-errors line 12.
<pre></pre>
<a name="bottom"></a><br><b>End of log</b><br>
</body></html>
It seems that the value of the domain is not being passed in correctly and it is
not being passed down through the script.
When I run the script as a cgi-bin script called from a web page I get the html
code produced by the print statements but I get nothing from the $tail variable.
This is what I would expect as I get nothing between the <pre></pre> tags when I
run it from a command line.
I would appreciate any help in sorting out this problem.
Regards,
Richard Luckhurst
| |
| usenet@DavidFilmer.com 2006-10-24, 3:56 am |
| Richard Luckhurst wrote:
> $tail = `tail -n2000 /var/log/httpd/$domain-error_log 2>/dev/null | tac`;
> I get nothing from the $tail variable.
Maybe it's because you never defined a value for $domain-error_log.
If you had put:
use strict; use warnings;
at the top of your program, Perl would have alerted you of this fact.
--
David Filmer (http://DavidFilmer.com)
| |
| Uri Guttman 2006-10-24, 3:56 am |
| >>>>> "RL" == Richard Luckhurst <rluckhurst@resmaster.com> writes:
RL> require '/www/server/cgi-bin/cgi-lib.pl';
that is a very old and broken library from perl4 days. use CGI.pm which
comes with all modern perls. and please stop what you are doing and get
a modern perl book. i don't know where you learned about using cgi-lib
but i am curious so we can find and nuke the source.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
| |
| usenet@DavidFilmer.com 2006-10-24, 3:56 am |
| Uri Guttman wrote:
> i don't know where you learned about using cgi-lib
I got the impression that the code was old production code. I think
there are lots of years-old programs using cgi-lib. Heck, I can think
of a number of them at my company...
--
David Filmer (http://DavidFilmer.com)
| |
| nobull67@gmail.com 2006-10-24, 3:56 am |
|
Richard Luckhurst wrote:
> I am a perl newbie.
>
> I have a small perl script that is actually a cgi-bin script.
What you have is a legacy Perl4 script.
> I am told that
> until a recent server change over it ran fine however now it produces no output.
> I have tried running it from a command line and redirecting the input it would
> have received as a cgi-bin script from a text file.
Have you? Are you sure?
> I am getting a couple of
> "Use of uninitialized value in concatenation (.) or string" errors and I can not
> see why.
>
> The script is as follows
>
> #!/usr/bin/perl
> #
> # log-errors cgi-bin script to display the last 2000 lines of an error log.
> # domain is the domain name of the virtual apache server
> #
The script was not written with warnings enabled, testing it with
warings enabled could produce spurious warnings that have nothing to do
with your problem. That said, this isn't what's happening here.
> require '/www/server/cgi-bin/cgi-lib.pl';
> &ReadParse(*in);
> $domain = $in{'domain'};
> When I run the script from the command line with the command
>
> perl -w log-err* < test.txt
>
> Where test.txt contains domain=www.resmaster.com
> I get the following output
> Use of uninitialized value in concatenation (.) or string at log-errors line 12.
> It seems that the value of the domain is not being passed in correctly and it is
> not being passed down through the script.
Hmmm... To properly simulate the CGI environment you need to set some
environment variables too. Perhaps the cgi-lib.pl does support an
alternate debug mode, perhaps it doesn't. So this may or may not be the
problem.
> When I run the script as a cgi-bin script called from a web page I get the html
> code produced by the print statements but I get nothing from the $tail variable.
So you are saying that you do see the value of $domain it's just $tail
that's empty? In that case the true problem is not related to the
setting of of the $domain.
> This is what I would expect as I get nothing between the <pre></pre> tags when I
> run it from a command line.
>
> I would appreciate any help in sorting out this problem.
Perhaps you should stop discarding the error from the tail command then
go look in the server logs to see what the problem was.
Of course, if you find the logs aren't where you recall them being or
you are no longer allowed to read them then I think you've just found
your problem right there!
Your script contains at least one major security hole that would allow
an attacker to execute arbitrary code on the web server. Rather than
simply delete this script your server admin may have decided to
"sandbox" your CGI scripts so that they can't do any damage. One side
effect could well be that your scripts can't get at the logs.
| |
| Rob Dixon 2006-10-24, 3:56 am |
| Richard Luckhurst wrote:
> Hi All
>
> I am a perl newbie.
>
> I have a small perl script that is actually a cgi-bin script. I am told that
> until a recent server change over it ran fine however now it produces no output.
> I have tried running it from a command line and redirecting the input it would
> have received as a cgi-bin script from a text file. I am getting a couple of
> "Use of uninitialized value in concatenation (.) or string" errors and I can not
> see why.
>
> The script is as follows
>
> #!/usr/bin/perl
> #
> # log-errors cgi-bin script to display the last 2000 lines of an error log.
> # domain is the domain name of the virtual apache server
> #
>
> require '/www/server/cgi-bin/cgi-lib.pl';
> &ReadParse(*in);
> $domain = $in{'domain'};
> print "Content-type: text/html\n\n";
> print "<html><head><title>Exodus Web Server Log</title></head>\n";
> print "<body link=\"blue\" vlink=\"blue\">\n";
> print "<font size=\"4\"><b>Last 2000 Lines of the Error log for: $domain</b></font><br>\n";
> print "<font size=\"1\"><br></font>Go to <a href=\"#bottom\"><i>End of log</i></a><br><br>\n";
> $tail = `tail -n2000 /var/log/httpd/$domain-error_log 2>/dev/null | tac`;
> $tail =~ s/</<\;/g;
> $tail =~ s/>/>\;/g;
> print "<pre>$tail<\/pre>\n";
> print "<a name=\"bottom\"></a>";
> print "<br><b>End of log</b><br>\n";
> print "</body></html>\n";
> exit 0;
>
>
> When I run the script from the command line with the command
>
> perl -w log-err* < test.txt
>
> Where test.txt contains domain=www.resmaster.com
>
> I get the following output
>
> Content-type: text/html
>
> <html><head><title>Exodus Web Server Log</title></head>
> <body link="blue" vlink="blue">
> Use of uninitialized value in concatenation (.) or string at log-errors line 10.
> <font size="4"><b>Last 2000 Lines of the Error log for: </b></font><br>
> <font size="1"><br></font>Go to <a href="#bottom"><i>End of log</i></a><br><br>
> Use of uninitialized value in concatenation (.) or string at log-errors line 12.
> <pre></pre>
> <a name="bottom"></a><br><b>End of log</b><br>
> </body></html>
>
> It seems that the value of the domain is not being passed in correctly and it is
> not being passed down through the script.
>
> When I run the script as a cgi-bin script called from a web page I get the html
> code produced by the print statements but I get nothing from the $tail variable.
> This is what I would expect as I get nothing between the <pre></pre> tags when I
> run it from a command line.
>
> I would appreciate any help in sorting out this problem.
Hello Richard
You are right that your problem is almost certainly because $domain is not being
set up properly, but the error lies in the ReadParse() subroutine in the
cgi-lib.pl file which you don't show. You are looking at a very old piece of
Perl programming which is doing things in ugly ways, so please don't try to
learn anything from its methods!
Rob
|
|
|
|