summaryrefslogtreecommitdiff
path: root/fml/lib
diff options
context:
space:
mode:
authorfukachan <fukachan>2004-01-31 14:12:17 +0000
committerfukachan <fukachan>2004-01-31 14:12:17 +0000
commit6e28ebb3b45eeb66895e5a5c000cf598fa44f68a (patch)
tree0e14202bb4ddfc08373f016f0cdfb86896994940 /fml/lib
parente822c0e0cf7e2f56513a7ab96eaaae6d0378f4a2 (diff)
downloadfml8-6e28ebb3b45eeb66895e5a5c000cf598fa44f68a.tar.gz
fml8-6e28ebb3b45eeb66895e5a5c000cf598fa44f68a.tar.bz2
fml8-6e28ebb3b45eeb66895e5a5c000cf598fa44f68a.zip
validate input address.
Diffstat (limited to 'fml/lib')
-rw-r--r--fml/lib/FML/Error/Cache.pm57
1 files changed, 44 insertions, 13 deletions
diff --git a/fml/lib/FML/Error/Cache.pm b/fml/lib/FML/Error/Cache.pm
index cf0af8bf..f434001b 100644
--- a/fml/lib/FML/Error/Cache.pm
+++ b/fml/lib/FML/Error/Cache.pm
@@ -4,7 +4,7 @@
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
-# $FML: Cache.pm,v 1.16 2004/01/01 08:44:48 fukachan Exp $
+# $FML: Cache.pm,v 1.17 2004/01/01 08:48:41 fukachan Exp $
#
package FML::Error::Cache;
@@ -145,9 +145,13 @@ sub add
return undef;
}
- # XXX-TODO: validate $address ?
if ($address) {
- $db->{ $address } = "$unixtime status=$status reason=$reason";
+ if ($self->_is_valid_address($address)) {
+ $db->{ $address } = "$unixtime status=$status reason=$reason";
+ }
+ else {
+ $curproc->logwarn("FML::Error::Cache: add: invalid address");
+ }
}
else {
$curproc->logwarn("FML::Error::Cache: add: invalid data");
@@ -181,9 +185,13 @@ sub delete
my $db = $self->{ _db };
if (defined $db) {
- # XXX-TODO: validate $address ?
if ($address) {
- delete $db->{ $address };
+ if ($self->_is_valid_address($address)) {
+ delete $db->{ $address };
+ }
+ else {
+ croak("FML::Error::Cache: delete: invalid address");
+ }
}
else {
$curproc->logwarn("FML::Error::Cache: delete: invalid data");
@@ -219,17 +227,21 @@ sub _open_cache
my ($self) = @_;
my $curproc = $self->{ _curproc };
my $config = $curproc->config();
- my $type = $config->{ error_analyzer_cache_type };
my $dir = $config->{ error_analyzer_cache_dir };
- my $mode = $config->{ error_analyzer_cache_mode } || 'temporal';
- my $days = $config->{ error_analyzer_cache_size } || 14;
- use Tie::JournaledDir;
+ # parameters: but not used now.
+ my %db = ();
+ my $type = $config->{ error_analyzer_cache_type };
+ my $mode = $config->{ error_analyzer_cache_mode } || 'temporal';
+ my $days = $config->{ error_analyzer_cache_size } || 14;
+ my $args = {
+ dir => $dir,
+ unit => 'day',
+ limit => $days,
+ };
- # XXX-TODO: use ? $type, $mode, $days
- # tie style
- my %db = ();
- tie %db, 'Tie::JournaledDir', { dir => $dir };
+ use Tie::JournaledDir;
+ tie %db, 'Tie::JournaledDir', $args;
$self->{ _db } = \%db;
}
@@ -294,6 +306,25 @@ sub get_all_values_as_hash_ref
}
+# Descriptions: check if the address is valid string?
+# Arguments: OBJ($self) STR($address)
+# Side Effects: none
+# Return Value: NUM
+sub _is_valid_address
+{
+ my ($self, $address) = @_;
+
+ use FML::Restriction::Base;
+ my $safe = new FML::Restriction::Base;
+ if ($safe->regexp_match('address', $address)) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+
=head1 CODING STYLE
See C<http://www.fml.org/software/FNF/> on fml coding style guide.