Subject: | Calls with static values to Float cause taint issues when used in taint mode. |
When running a script that generates PDF::API2 document with taint mode -wT, calls to float in
PDF/API2/Util.pm will cause a taint exception when passed to the ABS function.
In some cases these errors were reasonable, since they flowed down from user selected data
(like an image width). However calls to $text_object->translate( $xpos, $ypos ) with static
content would also generate an exception.
I found the attached patch solved the issues, by doing some simple validation on the floats,
which solved the taint issues for our team. Their may be further taint/validation problems else
where, but I have not found them yet.
Running on : MacOS X 10.7.4 perl 5, version 12, subversion 3 (v5.12.3) built for darwin-thread-
multi-2level
Subject: | pdf_api2_taint.patch |
--- PDF/API2/Util.pm 2011-03-10 15:46:12.000000000 -0800
+++ PDF/API2/Util.pm 2012-06-06 16:17:19.000000000 -0700
@@ -126,10 +126,20 @@
} else { return 0; }
}
+sub detaint_float {
+ my $match = $_[0] =~ /^([-+]?\d+[.]?\d*)$/s;
+ $_[0] = $match ? $1 : undef;
+ return (defined($_[0]));
+}
+
+
sub float {
my $f=shift @_;
my $mxd=shift @_||4;
$f=0 if(abs($f)<0.0000000000000001);
+
+ detaint_float($f);
+
my $ad=floor(xlog10($f)-$mxd);
if(abs($f-int($f)) < (10**(-$mxd))) {
# just in case we have an integer