]> granicus.if.org Git - p11-kit/commitdiff
Fix RPC calls: BYTE buffer not null and length 0
authorVincent JARDIN <vjardin@free.fr>
Tue, 22 Oct 2019 20:50:45 +0000 (22:50 +0200)
committerDaiki Ueno <ueno@gnu.org>
Sun, 27 Oct 2019 06:28:53 +0000 (07:28 +0100)
Let's add a support for cases when the buffer != NULL but the
length is 0. According to Oasis, buffer = NULL and length = 0
means a query of the length so the subsequent calls with a
buffer != NULL should fill buffer when length is long enough.
If not, according to Oasis, one should get a CKR_BUFFER_TOO_SMALL.

This current fix is for IN_BYTE_BUFFER(), same
for IN_ATTRIBUTE_BUFFER().

See the previous commit for IN_ULONG_BUFFER(). This patch is
strictly using the same design pattern.

Fix: issue #257

Suggested-by: Daiki Ueno <dueno@redhat.com>
p11-kit/rpc-client.c
p11-kit/rpc-message.c
p11-kit/rpc-message.h
p11-kit/rpc-server.c

index 7d7c2818a5eeeb22f73e49c325a32ed25a4580ac..5b8e76e55ac8996b298d8f73ac504f6969492cd9 100644 (file)
@@ -570,7 +570,7 @@ proto_read_sesssion_info (p11_rpc_message *msg,
 #define IN_BYTE_BUFFER(arr, len) \
        if (len == NULL) \
                { _ret = CKR_ARGUMENTS_BAD; goto _cleanup; } \
-       if (!p11_rpc_message_write_byte_buffer (&_msg, arr ? *len : 0)) \
+       if (!p11_rpc_message_write_byte_buffer (&_msg, arr, len)) \
                { _ret = CKR_HOST_MEMORY; goto _cleanup; }
 
 #define IN_BYTE_ARRAY(arr, len) \
index 95bf6cee540ff1a7e25dbd735ec0b1b1910a8106..3039a3d5d02fe030e8926595c634d721189c827f 100644 (file)
@@ -336,14 +336,16 @@ p11_rpc_message_write_ulong (p11_rpc_message *msg,
 
 bool
 p11_rpc_message_write_byte_buffer (p11_rpc_message *msg,
-                                   CK_ULONG count)
+                                   CK_BYTE_PTR array,
+                                   CK_ULONG_PTR n_array)
 {
        assert (msg != NULL);
        assert (msg->output != NULL);
 
        /* Make sure this is in the right order */
        assert (!msg->signature || p11_rpc_message_verify_part (msg, "fy"));
-       p11_rpc_buffer_add_uint32 (msg->output, count);
+       p11_rpc_buffer_add_byte (msg->output, array ? 0 : 1);
+       p11_rpc_buffer_add_uint32 (msg->output, *n_array);
        return !p11_buffer_failed (msg->output);
 }
 
index 9e1fe0fed00e81e49ecfd893938a50c396f71cdc..8601b9be62563d9f241421ee9be74f375e6fc707 100644 (file)
@@ -279,7 +279,8 @@ bool             p11_rpc_message_write_space_string      (p11_rpc_message *msg,
                                                                    CK_ULONG length);
 
 bool             p11_rpc_message_write_byte_buffer       (p11_rpc_message *msg,
-                                                          CK_ULONG count);
+                                                          CK_BYTE_PTR array,
+                                                          CK_ULONG_PTR n_array);
 
 bool             p11_rpc_message_write_byte_array        (p11_rpc_message *msg,
                                                           CK_BYTE_PTR arr,
index 37c2c54b2bd0b92a52dbbb96db036dd2692bd50f..764ad34087c08962f7174f1bb68af0f317665fc1 100644 (file)
@@ -68,6 +68,7 @@ proto_read_byte_buffer (p11_rpc_message *msg,
                         CK_ULONG *n_buffer)
 {
        uint32_t length;
+       uint8_t buffer_is_null;
 
        assert (msg != NULL);
        assert (buffer != NULL);
@@ -77,6 +78,8 @@ proto_read_byte_buffer (p11_rpc_message *msg,
        /* Check that we're supposed to be reading this at this point */
        assert (!msg->signature || p11_rpc_message_verify_part (msg, "fy"));
 
+       if (!p11_rpc_buffer_get_byte (msg->input, &msg->parsed, &buffer_is_null))
+               return PARSE_ERROR;
        /* The number of ulongs there's room for on the other end */
        if (!p11_rpc_buffer_get_uint32 (msg->input, &msg->parsed, &length))
                return PARSE_ERROR;
@@ -84,8 +87,8 @@ proto_read_byte_buffer (p11_rpc_message *msg,
        *n_buffer = length;
        *buffer = NULL;
 
-       /* If set to zero, then they just want the length */
-       if (length == 0)
+       /* If buffer is NULL, the caller just wants the length */
+       if (buffer_is_null)
                return CKR_OK;
 
        *buffer = p11_rpc_message_alloc_extra (msg, length * sizeof (CK_BYTE));