From 95c3d844be6d3d3ab60d2b0f17a72432309658fe Mon Sep 17 00:00:00 2001
From: Fredrik Thulin <fredrik@thulin.net>
Date: Mon, 17 Dec 2012 13:59:09 +0100
Subject: [PATCH] proto_read_byte_buffer: Allocate buffer even for 0 bytes.

Best for the proxy to be as transparent as possible. This fixes a test
case with C_GenerateRandom of 0 bytes, found in pkcs11-tool --test.
---
 gck-rpc-dispatch.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gck-rpc-dispatch.c b/gck-rpc-dispatch.c
index d694c52..902227c 100644
--- a/gck-rpc-dispatch.c
+++ b/gck-rpc-dispatch.c
@@ -214,9 +214,11 @@ proto_read_byte_buffer(CallState * cs, CK_BYTE_PTR * buffer,
 	*n_buffer = length;
 	*buffer = NULL;
 
-	/* If set to zero, then they just want the length */
-	if (!length)
-		return CKR_OK;
+	/* We go ahead and allocate a buffer even if length is zero. The code used
+	 * to just return CKR_OK without allocating a buffer, but that breaks a
+	 * test case in pkcs11-tool for C_GenerateRandom of 0 bytes. Best to be as
+	 * transparent as possible and let the p11 module decide how to handle it.
+	 */
 
 	*buffer = call_alloc(cs, length * sizeof(CK_BYTE));
 	if (!*buffer)
-- 
GitLab