T
Gunnar Hjalmarsson said:To me, a piece of code that does what it's _intended_ to do is not
"buggy". It may have _limitations_, but limitations and bugs are not
the same thing.
If I want my program to print today's date in ISO 8601 format, I may
use this code:
my $time = time;
sub myDate {
my @t = (gmtime $time)[3..5];
sprintf '%d-%02d-%02d', $t[2] += 1900, ++$t[1], $t[0];
}
print myDate();
I could have used your Time::Format module instead, but if I don't
need a variety of date and time formats in my program, I wouldn't
likely have done so.
Time::Format includes some nice tools for time formating, no doubt.
Nevertheless, that fact wouldn't make you claim that my myDate()
function is "buggy", right?
Tintin said:Gunnar said:To me, a piece of code that does what it's _intended_ to do is
not "buggy". It may have _limitations_, but limitations and bugs
are not the same thing.
If I want my program to print today's date in ISO 8601 format, I
may use this code:
my $time = time;
sub myDate {
my @t = (gmtime $time)[3..5];
sprintf '%d-%02d-%02d', $t[2] += 1900, ++$t[1], $t[0];
}
print myDate();
I could have used your Time::Format module instead, but if I
don't need a variety of date and time formats in my program, I
wouldn't likely have done so.
Time::Format includes some nice tools for time formating, no
doubt. Nevertheless, that fact wouldn't make you claim that my
myDate() function is "buggy", right?
Your analogy is not a good one. An ISO8601 date format has very
rigid parameters, whereas CGI data is by its very nature, variable.
Gunnar Hjalmarsson said:Tintin said:Gunnar said:To me, a piece of code that does what it's _intended_ to do is
not "buggy". It may have _limitations_, but limitations and bugs
are not the same thing.
If I want my program to print today's date in ISO 8601 format, I
may use this code:
my $time = time;
sub myDate {
my @t = (gmtime $time)[3..5];
sprintf '%d-%02d-%02d', $t[2] += 1900, ++$t[1], $t[0];
}
print myDate();
I could have used your Time::Format module instead, but if I
don't need a variety of date and time formats in my program, I
wouldn't likely have done so.
Time::Format includes some nice tools for time formating, no
doubt. Nevertheless, that fact wouldn't make you claim that my
myDate() function is "buggy", right?
Your analogy is not a good one. An ISO8601 date format has very
rigid parameters, whereas CGI data is by its very nature, variable.
True, but all potential variations are not applicable in all programs
that parse CGI data. For instance, if you want that a program only
parses POSTed data, it's not buggy because it isn't prepared to handle
potential variations in data submitted via GET. Limited? Yes.
Unflexible? Yes. Buggy? No.
The only point with my example was to illustrate that distinction.
Call a spade a spade!
True, but all potential variations are not applicable in all programs
that parse CGI data. For instance, if you want that a program only
parses POSTed data, it's not buggy because it isn't prepared to handle
potential variations in data submitted via GET. Limited? Yes.
Unflexible? Yes. Buggy? No.
Tintin said:I agree with you about not calling code buggy to a certain degree.
... however, the typical newbie or person that writes "limited" CGI
parsing code, generally does not write it deliberately with
limitations. In most cases, I think it is fair to say they are
writing code which they think works for all occasions.
Eric said:I just can't believe that anyone would advocate writing one's own
limited CGI parsing code from scratch, against using the robust,
flexible CGI.pm off the shelf.
I have a program, where I believe it would be indefensible to have it
load CGI.pm.
Maybe that's why I'm so sensible about this.
Randal said:You *do* realize that CGI.pm uses a "compile as you go" mechanism?
I'd bet it'd be hard to get something that is even *twice* as efficient
that has all the security provisions and knowledge accumulated over
the years in CGI.pm.
Please show me your code that is more than twice as efficient as CGI.pm,
and yet as still as secure.
Alan said:Then it's probably indefensible to run it from the traditional CGI
in the first place:
you should be looking to run it from mod_perl or other persistent
environment, where the overhead of loading CGI.pm is no longer of
any relevance since it's not being done per-invocation any more.
"sensitive", maybe.
"sensible"? - I'd have to reserve judgment until I saw the full
implications, including the security review and some sensible
assessment of the implications for long-term maintainability.
Purl said:A quick comment on this line above. All browsers submit
\r\n
when ENTER is pressed and the cursor is inside a text area box.
This is not specific to Windows, under those conditions.
Adding security features to your method, is so very easy. A quick
example for html enabled form input,
$value =~ s/`/`/g;
Purl said:Gunnar said:maybe I should have added that data submitted by users who are
not logged-in, and which ends up on generated HTML pages, is
converted by this sub:
sub htmlize {
$_[0] =~ s/&/&/g;
$_[0] =~ s/"/"/g;
$_[0] =~ s/</</g;
$_[0] =~ s/>/>/g;
return $_[0];
}
That conversion is done at a later stage, since (non-converted)
HTML is occationally included in email messages.
Wouldn't that take care of the risk with backticks as well?
As you know, the degree of risk of input data is directly related
to "what" a program does. If a program does not call any functions
susceptable to backtick syntax, no problem.
Contrasting this, our Chahta Chat is susceptable to hostile html
tags. Nonetheless, we want our visitors to be able to enjoy fancy
fonts, colors, pictures and all that.
For html, like you, processing outside a read and parse takes care
of this.
my (@bad_word_list) = ("<applet", "<blockquote", "<body", "<dl", "<form",
"<head", "<html", "<ol", "<object", "<plaintext",
"<script", "<strike", "<xmp", "<ul", "<h1", "<h2",
"<h3", "<h4", "<h5", "<h6", "|/", "<embed",
"face=symbol", "face=system", "strnps", ... others
One situation where doing so makes sense is when efficiency matters.
I have a program, where I believe it would be indefensible to have it
load CGI.pm. Maybe that's why I'm so sensible about this.
This method you display will be a minimum eight-hundred percent
more efficient than CGI.pm and will be an average, a very large
average, one-thousand-three-hundred percent more efficient.
That is one-hundred-thirty times faster, not just twice as fast.
Eric said:If I recall correctly, CGI.pm has only about 200 lines of code that
gets compiled when the module is first loaded. If the time it
takes to compile those 200 lines makes a difference in the
execution of your program, then I suspect Perl/CGI is the wrong
technology to be using. I'd suggest mod_perl, FastCGI, or
maybe even writing the CGI input parsing code in C and loading it
via XS.
What sort of timing did you use to determine that CGI.pm was
slowing you down?
None.
It's just that the program by its very nature may be used in such a
way that repeated calls put quite some load on the server. For that
reason I'm trying to avoid unnecessary load, and since I have already
"reinvented the wheel", keeping to not using CGI.pm is an easy
contribution to that goal.
Eric said:Wait, let me get this straight -- you have no idea whether CGI.pm
is faster or slower than your own code, yet you choose to stick to
your own code in the belief that it contributes to your goal of
avoiding unnecessary load?
Gunnar Hjalmarsson said:Yes, I have an idea. I'm sure that CGI.pm is slower. Thought the code
I posted made that apparent to anybody who has an idea of what CGI.pm
is about.
Ben said:By no means.
In general, guessing that a particular piece of code will run
slower or faster than another is a dodgy business. The *only* way
to tell is to run benchmarks.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.