[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GT] Input validation in Tools.pm



I was just playing with a new installation of GT. One of the issues I came across is the available_timeframes directive supported by genericdbi.pm.  I was putting invalid timeframe names in that and was getting some cryptic warnings as a result.

The attached patch validates that situation.
--- /tmp/Tools-HEAD.pm	2008-07-01 17:39:28.000000000 +0100
+++ GT/Tools.pm	2008-07-01 15:24:33.000000000 +0100
@@ -435,8 +435,13 @@
 die("Parameter \$db not set in get_timeframe_data") if (!defined($db));
 
 if (defined($available_timeframes)) {
-	foreach (split(',', $available_timeframes)) {
-		push @tf, GT::DateTime::name_to_timeframe($_);
+	foreach my $tf_name (split(',', $available_timeframes)) {
+	        my $tf_code = GT::DateTime::name_to_timeframe($tf_name);
+		push @tf, $tf_code;
+		if (!defined($tf_code)) {
+		    my $tfs = join("\n\t", map(GT::DateTime::name_of_timeframe($_), GT::DateTime::list_of_timeframe));
+		    die("Invalid timeframe name in available_timeframes configuration item: $tf_name\n\nValid timeframes are: \n\t" . $tfs . "\n\n");
+		}
 	}
 	@tf = sort(@tf);
 } else {