From 98eec86cf38e3529b3b2f6dbd438b9ae7afa7155 Mon Sep 17 00:00:00 2001
From: Fredrik Thulin <fredrik@thulin.net>
Date: Fri, 21 Dec 2012 14:46:49 +0100
Subject: [PATCH] proto_read_byte_array: Don't pass size_t to
 egg_buffer_get_uint32.

Passing size_t to _get_uint32 might leave garbage in top 32 bits of size_t
on 64 bits platforms. While initializing the size_t to 0 would probably
work, using a temporary uint32_t and casting that is more explicit IMO.
---
 gck-rpc-dispatch.c | 5 +++--
 gck-rpc-module.c   | 6 ++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gck-rpc-dispatch.c b/gck-rpc-dispatch.c
index 0b7aa0d..67ea0aa 100644
--- a/gck-rpc-dispatch.c
+++ b/gck-rpc-dispatch.c
@@ -257,11 +257,12 @@ proto_read_byte_array(CallState * cs, CK_BYTE_PTR * array, CK_ULONG * n_array)
 		return PARSE_ERROR;
 
 	if (!valid) {
+		uint32_t n_size;
 		/* No array, no data, just length */
 		if (!egg_buffer_get_uint32
-		    (&msg->buffer, msg->parsed, &msg->parsed, &n_data))
+		    (&msg->buffer, msg->parsed, &msg->parsed, &n_size))
 			return PARSE_ERROR;
-		*n_array = n_data;
+		*n_array = (size_t) n_size;
 		*array = NULL;
 		return CKR_OK;
 	}
diff --git a/gck-rpc-module.c b/gck-rpc-module.c
index a7a522e..27b4145 100644
--- a/gck-rpc-module.c
+++ b/gck-rpc-module.c
@@ -826,12 +826,14 @@ proto_read_byte_array(GckRpcMessage * msg, CK_BYTE_PTR arr,
 
 	/* If not valid, then just the length is encoded, this can signify CKR_BUFFER_TOO_SMALL */
 	if (!valid) {
+		uint32_t t_len;
+
 		if (!egg_buffer_get_uint32
 		    (&msg->buffer, msg->parsed, &msg->parsed,
-		     (uint32_t *) & vlen))
+		     & t_len))
 			return PARSE_ERROR;
 
-		*len = vlen;
+		*len = t_len;
 
 		if (arr)
 			return CKR_BUFFER_TOO_SMALL;
-- 
GitLab