changeset 20567:307eb07fba9c

lib-dcrypt: add crashing 8 byte garbage read test
author Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
date Mon, 25 Jul 2016 14:04:47 +0300
parents 6ebb03fc9a25
children 35e1cd019773
files src/lib-dcrypt/test-stream.c
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dcrypt/test-stream.c	Fri Jul 15 16:31:01 2016 +0300
+++ b/src/lib-dcrypt/test-stream.c	Mon Jul 25 14:04:47 2016 +0300
@@ -392,6 +392,29 @@
 	test_end();
 }
 
+static int no_op_cb(const char *digest ATTR_UNUSED,
+		struct dcrypt_private_key **priv_key_r ATTR_UNUSED,
+		const char **error_r ATTR_UNUSED,
+		void *context ATTR_UNUSED)
+{
+	return 0;
+}
+
+static void test_read_8byte_garbage(void)
+{
+	test_begin("test_read_8byte_garbage");
+
+	struct istream *is = i_stream_create_from_data("12345678", 8);
+	struct istream *ds = i_stream_create_decrypt_callback(is,
+			no_op_cb, NULL);
+	ssize_t siz = i_stream_read(ds);
+	test_assert(siz < 0);
+	i_stream_unref(&ds);
+	i_stream_unref(&is);
+
+	test_end();
+}
+
 static
 void test_free_keys() {
 	dcrypt_key_unref_private(&test_v1_kp.priv);
@@ -420,6 +443,7 @@
 		test_write_read_v2_short,
 		test_write_read_v2_empty,
 		test_free_keys,
+		test_read_8byte_garbage,
 		NULL
 	};