You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/07/07 20:24:48 UTC
svn commit: r554237 - in /spamassassin/branches/3.2: spamc/libspamc.c
spamc/spamc.c t/SATest.pm t/spamc_x_E_R.t t/spamc_x_e.t
Author: jm
Date: Sat Jul 7 11:24:47 2007
New Revision: 554237
URL: http://svn.apache.org/viewvc?view=rev&rev=554237
Log:
bug 5412: 'spamc -x -R' always returned 0, instead
of the exit code, on error. Bug 5478: in addition, 'spamc -x -e /command' would
still run the command, even if errors meant that the filtered text would be
unavailable, which contradicted -x. fixed
Added:
spamassassin/branches/3.2/t/spamc_x_E_R.t (with props)
spamassassin/branches/3.2/t/spamc_x_e.t
Modified:
spamassassin/branches/3.2/spamc/libspamc.c
spamassassin/branches/3.2/spamc/spamc.c
spamassassin/branches/3.2/t/SATest.pm
Modified: spamassassin/branches/3.2/spamc/libspamc.c
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/spamc/libspamc.c?view=diff&rev=554237&r1=554236&r2=554237
==============================================================================
--- spamassassin/branches/3.2/spamc/libspamc.c (original)
+++ spamassassin/branches/3.2/spamc/libspamc.c Sat Jul 7 11:24:47 2007
@@ -504,7 +504,18 @@
family, host, port, numloops + 1, connect_retries);
#endif
- status = timeout_connect(mysock, res->ai_addr, res->ai_addrlen);
+ /* this is special-cased so that we have an address we can
+ * safely use as an "always fail" test case */
+ if (!strcmp(host, "255.255.255.255")) {
+ libspamc_log(tp->flags, LOG_ERR,
+ "connect to spamd on %s failed, broadcast addr",
+ host);
+ status = -1;
+ }
+ else {
+ status = timeout_connect(mysock, res->ai_addr, res->ai_addrlen);
+ }
+
#else
struct sockaddr_in addrbuf;
const char *ipaddr;
@@ -524,11 +535,21 @@
"dbg: connect(AF_INET) to spamd at %s (try #%d of %d)",
ipaddr, numloops + 1, connect_retries);
#endif
-
- status =
- timeout_connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
-#endif
+ /* this is special-cased so that we have an address we can
+ * safely use as an "always fail" test case */
+ if (!strcmp(ipaddr, "255.255.255.255")) {
+ libspamc_log(tp->flags, LOG_ERR,
+ "connect to spamd on %s failed, broadcast addr",
+ ipaddr);
+ status = -1;
+ }
+ else {
+ status = timeout_connect(mysock, (struct sockaddr *) &addrbuf,
+ sizeof(addrbuf));
+ }
+
+#endif
if (status != 0) {
origerr = spamc_get_errno();
Modified: spamassassin/branches/3.2/spamc/spamc.c
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/spamc/spamc.c?view=diff&rev=554237&r1=554236&r2=554237
==============================================================================
--- spamassassin/branches/3.2/spamc/spamc.c (original)
+++ spamassassin/branches/3.2/spamc/spamc.c Sat Jul 7 11:24:47 2007
@@ -709,8 +709,8 @@
struct transport trans;
struct message m;
int out_fd = -1;
- int result;
- int ret;
+ int result = EX_SOFTWARE;
+ int ret = EX_SOFTWARE;
int extratype = 0;
int islearned = 0;
int isreported = 0;
@@ -927,44 +927,44 @@
free(username);
/* FAIL: */
- get_output_fd(&out_fd);
-
+#if 1
result = m.is_spam;
- if ((flags & SPAMC_CHECK_ONLY) && result != EX_TOOBIG) {
- /* probably, the write to stdout failed; we can still report exit code */
- message_cleanup(&m);
- ret = result;
- }
- else if (flags & (SPAMC_CHECK_ONLY | SPAMC_REPORT | SPAMC_REPORT_IFSPAM)) {
- full_write(out_fd, 1, "0/0\n", 4);
- message_cleanup(&m);
- ret = EX_NOTSPAM;
- }
- else if (flags & (SPAMC_LEARN|SPAMC_PING) ) {
- message_cleanup(&m);
+ if (ret != EX_OK) {
+ result = ret;
}
- else if (flags & SPAMC_SYMBOLS) {
- /* bug 4991: -y should only output a blank line on connection failure */
- full_write(out_fd, 1, "\n", 1);
+#endif
+ if (flags & (SPAMC_LEARN|SPAMC_PING) ) {
+ get_output_fd(&out_fd);
message_cleanup(&m);
- if (use_exit_code) {
- ret = result;
- }
- else if (flags & SPAMC_SAFE_FALLBACK) {
- ret = EX_OK;
- }
}
else {
- message_dump(STDIN_FILENO, out_fd, &m);
+ if (flags & (SPAMC_CHECK_ONLY | SPAMC_REPORT | SPAMC_REPORT_IFSPAM)) {
+ get_output_fd(&out_fd);
+ full_write(out_fd, 1, "0/0\n", 4);
+ }
+ else if (flags & SPAMC_SYMBOLS) {
+ /* bug 4991: -y should only output a blank line on connection failure */
+ get_output_fd(&out_fd);
+ full_write(out_fd, 1, "\n", 1);
+ }
+ else {
+ /* bug 5412: spamc -x should not output the message on error */
+ if ((flags & SPAMC_SAFE_FALLBACK) || result == EX_TOOBIG) {
+ get_output_fd(&out_fd);
+ message_dump(STDIN_FILENO, out_fd, &m);
+ }
+ /* else, do NOT get_output_fd() (bug 5478) */
+ }
+
message_cleanup(&m);
if (ret == EX_TOOBIG) {
- ret = 0;
+ ret = EX_OK; /* too big always means exit(0) -- bug 5412 */
}
- else if (use_exit_code) {
- ret = result;
- }
else if (flags & SPAMC_SAFE_FALLBACK) {
ret = EX_OK;
+ }
+ else if (use_exit_code) {
+ ret = result;
}
}
Modified: spamassassin/branches/3.2/t/SATest.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/t/SATest.pm?view=diff&rev=554237&r1=554236&r2=554237
==============================================================================
--- spamassassin/branches/3.2/t/SATest.pm (original)
+++ spamassassin/branches/3.2/t/SATest.pm Sat Jul 7 11:24:47 2007
@@ -316,11 +316,15 @@
sub scrunwithstderr {
spamcrun (@_, 1);
}
+sub scrunwantfail {
+ spamcrun (@_, 1, 1);
+}
sub spamcrun {
my $args = shift;
my $read_sub = shift;
my $capture_stderr = shift;
+ my $expect_failure = shift;
if (defined $ENV{'SC_ARGS'}) {
$args = $ENV{'SC_ARGS'} . " ". $args;
@@ -350,13 +354,19 @@
}
$sa_exitcode = ($?>>8);
- if ($sa_exitcode != 0) { stop_spamd(); return undef; }
+ if (!$expect_failure) {
+ if ($sa_exitcode != 0) { stop_spamd(); return undef; }
+ }
%found = ();
%found_anti = ();
&checkfile ("d.$testname/out.${Test::ntest}", $read_sub) if (defined $read_sub);
- ($sa_exitcode == 0);
+ if ($expect_failure) {
+ ($sa_exitcode != 0);
+ } else {
+ ($sa_exitcode == 0);
+ }
}
sub spamcrun_background {
Added: spamassassin/branches/3.2/t/spamc_x_E_R.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/t/spamc_x_E_R.t?view=auto&rev=554237
==============================================================================
--- spamassassin/branches/3.2/t/spamc_x_E_R.t (added)
+++ spamassassin/branches/3.2/t/spamc_x_E_R.t Sat Jul 7 11:24:47 2007
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("spamc_x_E_R");
+
+our $DO_RUN = !$SKIP_SPAMD_TESTS;
+
+use Test; plan tests => ($DO_RUN ? 49 : 0);
+
+exit unless $DO_RUN;
+
+# ---------------------------------------------------------------------------
+# test case for bug 5412; exit status with -x/-E/-R combos
+
+%patterns = ( );
+
+ok(start_spamd("-L"));
+
+# ----------------------------------------------------------------------
+# nonspam mails -- return 0
+ok(scrun("-E < data/nice/001", \&patterns_run_cb));
+ok(scrun("-R < data/nice/001", \&patterns_run_cb));
+ok(scrun("-x -E < data/nice/001", \&patterns_run_cb));
+ok(scrun("-x -R < data/nice/001", \&patterns_run_cb));
+ok(scrun("-x -R -E < data/nice/001", \&patterns_run_cb));
+
+# ----------------------------------------------------------------------
+# spam mails
+ok(scrun("-R < data/spam/001", \&patterns_run_cb));
+ok(scrun("-x -R < data/spam/001", \&patterns_run_cb));
+
+# returns 1; this will kill spamd as a side-effect
+ok(scrunwantfail("-x -E < data/spam/001", \&patterns_run_cb));
+stop_spamd(); $spamd_pid = undef; $spamd_already_killed = undef;
+ok(start_spamd("-L"));
+
+# returns 1; this will kill spamd
+ok(scrunwantfail("-E < data/spam/001", \&patterns_run_cb));
+stop_spamd(); $spamd_pid = undef; $spamd_already_killed = undef;
+ok(start_spamd("-L"));
+
+# returns 1; this will kill spamd
+ok(scrunwantfail("-x -R -E < data/spam/001", \&patterns_run_cb));
+stop_spamd(); # just to be sure
+
+# ----------------------------------------------------------------------
+# error conditions
+# max-size of 512 bytes; EX_TOOBIG, pass through message despite -x
+
+%patterns = (
+ q{ Subject: There yours for FREE!}, 'subj',
+);
+%anti_patterns = (
+ q{ X-Spam-Flag: }, 'flag',
+);
+
+# this should have exit code == 0, and pass through the full
+# unfiltered text
+clear_pattern_counters();
+ok(scrun("-s 512 -x < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+# this should have exit code == 0, and pass through the full
+# unfiltered text
+clear_pattern_counters();
+ok(scrun("-s 512 -x -E < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+%patterns = (
+ q{ 0/0 }, '0/0',
+);
+%anti_patterns = (
+ q{ Subject: There yours for FREE!}, 'subj',
+ q{ X-Spam-Flag: }, 'flag',
+);
+
+# this should have exit code == 0, and emit "0/0"
+clear_pattern_counters();
+ok(scrun("-s 512 -x -R < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+# this should have exit code == 0, and emit "0/0"
+clear_pattern_counters();
+ok(scrun("-s 512 -x -E -R < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+# ----------------------------------------------------------------------
+
+$spamdhost = '255.255.255.255'; # cause "connection failed" errors
+
+# these should have exit code == 0
+ok(scrun("--connect-retries 1 -E < data/spam/001", \&patterns_run_cb));
+ok(scrun("--connect-retries 1 -R < data/spam/001", \&patterns_run_cb));
+
+# we do not want to see the output with -x on error
+%patterns = ();
+%anti_patterns = (
+ q{ Subject: There yours for FREE!}, 'subj',
+ q{ X-Spam-Flag: YES}, 'flag',
+);
+
+# this should have exit code != 0
+clear_pattern_counters();
+ok(scrunwantfail("--connect-retries 1 -x < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+# this should have exit code != 0
+clear_pattern_counters();
+ok(scrunwantfail("--connect-retries 1 -x -R < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+# this should have exit code != 0
+clear_pattern_counters();
+ok(scrunwantfail("--connect-retries 1 -x -E -R < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
+
+# this should have exit code != 0
+clear_pattern_counters();
+ok(scrunwantfail("--connect-retries 1 -x -E < data/spam/001", \&patterns_run_cb));
+ok ok_all_patterns();
Propchange: spamassassin/branches/3.2/t/spamc_x_E_R.t
------------------------------------------------------------------------------
svn:executable = *
Added: spamassassin/branches/3.2/t/spamc_x_e.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/t/spamc_x_e.t?view=auto&rev=554237
==============================================================================
--- spamassassin/branches/3.2/t/spamc_x_e.t (added)
+++ spamassassin/branches/3.2/t/spamc_x_e.t Sat Jul 7 11:24:47 2007
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("spamc_x_e");
+
+our $DO_RUN = !$SKIP_SPAMD_TESTS;
+
+use Test; plan tests => ($DO_RUN ? 7 : 0);
+
+exit unless $DO_RUN;
+
+# ---------------------------------------------------------------------------
+# test case for bug 5478: spamc -x -e
+
+%patterns = ( 'Fine' => 'Fine' );
+
+ok start_spamd("-L");
+ok spamcrun("-x -e /bin/echo Fine < data/nice/001", \&patterns_run_cb);
+ok ok_all_patterns();
+stop_spamd();
+
+%patterns = ( );
+%anti_patterns = ( 'Fine' => 'Fine' );
+$spamdhost = '255.255.255.255'; # cause "connection failed" errors
+
+ok !spamcrun("-x -e /bin/echo Fine < data/nice/001", \&patterns_run_cb);
+ok ok_all_patterns();
+