From 492ffd9897e4ea3ed8f205d5b84c9e1321ca3c58 Mon Sep 17 00:00:00 2001 From: brectanus Date: Thu, 31 Jul 2008 22:36:24 +0000 Subject: [PATCH] Sync up branches/2.5.x and trunk. --- CHANGES | 6 ++ apache2/apache2_util.c | 15 +++- apache2/modsecurity.h | 2 +- apache2/t/run-tests.pl.in | 157 -------------------------------------- 4 files changed, 18 insertions(+), 162 deletions(-) delete mode 100755 apache2/t/run-tests.pl.in diff --git a/CHANGES b/CHANGES index 6c4ff99c..88faeb26 100644 --- a/CHANGES +++ b/CHANGES @@ -84,6 +84,12 @@ * Make sure the apache include directory is included during build. +02 Apr 2008 - 2.1.7 +------------------- + + * Make sure temporary filehandles are closed after a transaction. + + 14 Mar 2008 - 2.5.1 ------------------- diff --git a/apache2/apache2_util.c b/apache2/apache2_util.c index 00854ed0..19c7de84 100644 --- a/apache2/apache2_util.c +++ b/apache2/apache2_util.c @@ -113,7 +113,10 @@ int apache2_exec(modsec_rec *msr, const char *command, const char **argv, char * apr_procattr_io_set(procattr, APR_NO_PIPE, APR_FULL_BLOCK, APR_NO_PIPE); apr_procattr_cmdtype_set(procattr, APR_SHELLCMD); - msr_log(msr, 9, "Exec: %s", log_escape_nq(r->pool, command)); + if (msr->txcfg->debuglog_level >= 9) { + msr_log(msr, 9, "Exec: %s", log_escape_nq(r->pool, command)); + } + rc = apr_proc_create(procnew, command, argv, env, procattr, r->pool); if (rc != APR_SUCCESS) { msr_log(msr, 1, "Exec: Execution failed: %s (%s)", log_escape_nq(r->pool, command), @@ -148,8 +151,10 @@ int apache2_exec(modsec_rec *msr, const char *command, const char **argv, char * p++; } - msr_log(msr, 4, "Exec: First line from script output: \"%s\"", - log_escape(r->pool, buf)); + if (msr->txcfg->debuglog_level >= 4) { + msr_log(msr, 4, "Exec: First line from script output: \"%s\"", + log_escape(r->pool, buf)); + } if (output != NULL) *output = apr_pstrdup(r->pool, buf); @@ -198,7 +203,9 @@ void record_time_checkpoint(modsec_rec *msr, int checkpoint_no) { apr_snprintf(note_name, 99, "mod_security-time%d", checkpoint_no); apr_table_set(msr->r->notes, note_name, note); - msr_log(msr, 4, "Time #%d: %s", checkpoint_no, note); + if (msr->txcfg->debuglog_level >= 4) { + msr_log(msr, 4, "Time #%d: %s", checkpoint_no, note); + } } /** diff --git a/apache2/modsecurity.h b/apache2/modsecurity.h index bf52a2e5..32f94f01 100644 --- a/apache2/modsecurity.h +++ b/apache2/modsecurity.h @@ -75,7 +75,7 @@ extern DSOLOCAL modsec_build_type_rec modsec_build_type[]; #define MODSEC_VERSION_MAJOR "2" #define MODSEC_VERSION_MINOR "5" #define MODSEC_VERSION_MAINT "7" -#define MODSEC_VERSION_TYPE "dev" +#define MODSEC_VERSION_TYPE "-dev" #define MODSEC_VERSION_RELEASE "1" #define MODULE_NAME "ModSecurity for Apache" diff --git a/apache2/t/run-tests.pl.in b/apache2/t/run-tests.pl.in deleted file mode 100755 index 238cac29..00000000 --- a/apache2/t/run-tests.pl.in +++ /dev/null @@ -1,157 +0,0 @@ -#!@PERL@ -# -# Run unit tests. -# -# Syntax: -# All: run-tests.pl -# All in file: run-tests.pl file -# Nth in file: run-tests.pl file N -# -use strict; -use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG); -use File::Basename qw(basename dirname); -use FileHandle; -use IPC::Open2 qw(open2); - -my @TYPES = qw(tfn op); -my $TEST = "./msc_test"; -my $SCRIPT = basename($0); -my $SCRIPTDIR = dirname($0); -my $PASSED = 0; -my $TOTAL = 0; - -if (defined $ARGV[0]) { - runfile(dirname($ARGV[0]), basename($ARGV[0]), $ARGV[1]); - done(); -} - -for my $type (sort @TYPES) { - my $dir = "$SCRIPTDIR/$type"; - my @cfg = (); - - # Get test names - opendir(DIR, "$dir") or quit(1, "Failed to open \"$dir\": $!"); - @cfg = grep { /\.t$/ && -f "$dir/$_" } readdir(DIR); - closedir(DIR); - - for my $cfg (sort @cfg) { - runfile($dir, $cfg); - } - -} -done(); - - -sub runfile { - my($dir, $cfg, $testnum) = @_; - my $fn = "$dir/$cfg"; - my @data = (); - my $edata; - my @C = (); - my @test = (); - my $teststr; - my $n = 0; - my $pass = 0; - - open(CFG, "<$fn") or quit(1, "Failed to open \"$fn\": $!"); - @data = ; - - $edata = q/@C = (/ . join("", @data) . q/)/; - eval $edata; - quit(1, "Failed to read test data \"$cfg\": $@") if ($@); - - unless (@C) { - msg("\nNo tests defined for $fn"); - return; - } - - msg("\nLoaded ".@C." tests from $fn"); - for my $t (@C) { - $n++; - next if (defined $testnum and $n != $testnum); - - my %t = %{$t || {}}; - my $id = sprintf("%6d", $n); - my $in = $t{input}; - my $out; - my $test_in = new FileHandle(); - my $test_out = new FileHandle(); - my $test_pid; - my $rc = 0; - my $param; - - if ($t{type} eq "tfn") { - $param = escape($t{output}); - } - elsif ($t{type} eq "op") { - $param = escape($t{param}); - } - else { - quit(1, "Unknown type \"$t{type}\" - should be one of: " . join(",",@TYPES)); - } - - @test = ($t{type}, $t{name}, $param, (exists($t{ret}) ? ($t{ret}) : ())); - $teststr = "$TEST " . join(" ", map { "\"$_\"" } @test); - $test_pid = open2($test_out, $test_in, $TEST, @test) or quit(1, "Failed to execute test: $teststr\": $!"); - print $test_in "$in"; - close $test_in; - $out = join("\\n", split(/\n/, <$test_out>)); - close $test_out; - waitpid($test_pid, 0); - - $rc = $?; - if ( WIFEXITED($rc) ) { - $rc = WEXITSTATUS($rc); - } - elsif( WIFSIGNALED($rc) ) { - msg("Test exited with signal " . WTERMSIG($rc) . "."); - msg("Executed: $teststr"); - $rc = -1; - } - else { - msg("Test exited with unknown error."); - $rc = -1; - } - - if ($rc == 0) { - $pass++; - } - - msg(sprintf("%s) %s \"%s\": %s%s", $id, $t{type}, $t{name}, ($rc ? "failed" : "passed"), ((defined($out) && $out ne "")? " ($out)" : ""))); - - } - - $TOTAL += $testnum ? 1 : $n; - $PASSED += $pass; - - msg(sprintf("Passed: %2d; Failed: %2d", $pass, $testnum ? (1 - $pass) : ($n - $pass))); -} - -sub escape { - my @new = (); - for my $c (split(//, $_[0])) { - push @new, ((ord($c) >= 0x20 and ord($c) <= 0x7e) ? $c : sprintf("\\x%02x", ord($c))); - } - join('', @new); -} - -sub msg { - print STDOUT "@_\n" if (@_); -} - -sub quit { - my($ec,$msg) = @_; - $ec = 0 unless (defined $_[0]); - - msg("$msg") if (defined $msg); - - exit $ec; -} - -sub done { - if ($PASSED != $TOTAL) { - quit(1, "\n$PASSED/$TOTAL tests passed."); - } - - quit(0, "\nAll tests passed ($TOTAL)."); -}