Add helper function zero_malloc for tests
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index 2be5dcc..d656519 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -102,11 +102,32 @@
}
/**
+ * Allocate and zeroize a buffer.
+ *
+ * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
+ *
+ * For convenience, dies if allocation fails.
+ */
+static unsigned char *zero_alloc( size_t len )
+{
+ void *p;
+ size_t actual_len = len != 0 ? len : 1;
+
+ assert( ( p = polarssl_malloc( actual_len ) ) != NULL );
+
+ memset( p, 0x00, actual_len );
+
+ return( p );
+}
+
+/**
* Allocate and fill a buffer from hex data.
*
* The buffer is sized exactly as needed. This allows to detect buffer
* overruns (including overreads) when running the test suite under valgrind.
*
+ * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
+ *
* For convenience, dies if allocation fails.
*/
static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
@@ -115,6 +136,9 @@
*olen = strlen(ibuf) / 2;
+ if( *olen == 0 )
+ return( zero_alloc( *olen ) );
+
assert( ( obuf = polarssl_malloc( *olen ) ) != NULL );
(void) unhexify( obuf, ibuf );