dovecot-2.2: lib: test fatal cases for printf_format_fix

dovecot at dovecot.org dovecot at dovecot.org
Wed Jul 30 12:04:02 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/84ead9b26d59
changeset: 17671:84ead9b26d59
user:      Phil Carmody <phil at dovecot.fi>
date:      Wed Jul 30 15:01:29 2014 +0300
description:
lib: test fatal cases for printf_format_fix
Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/test-lib.c               |   1 +
 src/lib/test-lib.h               |   1 +
 src/lib/test-printf-format-fix.c |  24 +++++++++++++++++++++++-
 3 files changed, 25 insertions(+), 1 deletions(-)

diffs (54 lines):

diff -r 16761cdb2537 -r 84ead9b26d59 src/lib/test-lib.c
--- a/src/lib/test-lib.c	Wed Jul 30 15:01:29 2014 +0300
+++ b/src/lib/test-lib.c	Wed Jul 30 15:01:29 2014 +0300
@@ -49,6 +49,7 @@
 	};
 	static enum fatal_test_state (*fatal_functions[])(int) = {
 		fatal_mempool,
+		fatal_printf_format_fix,
 		NULL
 	};
 	return test_run_with_fatals(test_functions, fatal_functions);
diff -r 16761cdb2537 -r 84ead9b26d59 src/lib/test-lib.h
--- a/src/lib/test-lib.h	Wed Jul 30 15:01:29 2014 +0300
+++ b/src/lib/test-lib.h	Wed Jul 30 15:01:29 2014 +0300
@@ -33,6 +33,7 @@
 void test_ostream_file(void);
 void test_primes(void);
 void test_printf_format_fix(void);
+enum fatal_test_state fatal_printf_format_fix(int);
 void test_priorityq(void);
 void test_seq_range_array(void);
 void test_str(void);
diff -r 16761cdb2537 -r 84ead9b26d59 src/lib/test-printf-format-fix.c
--- a/src/lib/test-printf-format-fix.c	Wed Jul 30 15:01:29 2014 +0300
+++ b/src/lib/test-printf-format-fix.c	Wed Jul 30 15:01:29 2014 +0300
@@ -92,5 +92,27 @@
 {
 	test_unchanged();
 	test_ok_changes();
-	/* want to test the panics too */
 }
+
+/* Want to test the panics too? go for it! */
+enum fatal_test_state fatal_printf_format_fix(int stage)
+{
+	static const char *fatals[] = {
+		"no no no %n's",
+		"%m allowed once, but not twice: %m",
+		"%m must not obscure a later %n",
+		"definitely can't have a tailing %",
+	};
+
+	if((unsigned int)stage >= N_ELEMENTS(fatals)) {
+		test_end();
+		return FATAL_TEST_FINISHED;
+	}
+
+	if(stage == 0)
+		test_begin("fatal_printf_format_fix");
+
+	/* let's crash! */
+	(void)printf_format_fix(fatals[stage]);
+	return FATAL_TEST_FAILURE;
+}


More information about the dovecot-cvs mailing list