Skip to content

Commit

Permalink
rpc: remove length assert in proto_read_attribute_buffer_array
Browse files Browse the repository at this point in the history
Signed-off-by: Zoltan Fridrich <[email protected]>
  • Loading branch information
ZoltanFridrich committed Mar 20, 2024
1 parent f53bdc2 commit c7f12e2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions p11-kit/rpc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ proto_read_attribute_buffer_array (p11_rpc_message *msg,
CK_ATTRIBUTE_PTR attrs, array;
CK_ULONG n_array;
uint32_t n_attrs, i;
uint32_t value;
uint32_t type, length;

/* Read the number of attributes */
if (!p11_rpc_buffer_get_uint32 (msg->input, &msg->parsed, &n_attrs))
Expand All @@ -270,30 +270,32 @@ proto_read_attribute_buffer_array (p11_rpc_message *msg,
for (i = 0; i < n_attrs; ++i) {

/* The attribute type */
if (!p11_rpc_buffer_get_uint32 (msg->input, &msg->parsed, &value))
if (!p11_rpc_buffer_get_uint32 (msg->input, &msg->parsed, &type))
return PARSE_ERROR;

attrs[i].type = value;
attrs[i].type = type;

/* The number of bytes to allocate */
if (!p11_rpc_buffer_get_uint32 (msg->input, &msg->parsed, &value))
if (!p11_rpc_buffer_get_uint32 (msg->input, &msg->parsed, &length))
return PARSE_ERROR;

if (value == 0) {
if (length == 0) {
attrs[i].pValue = NULL;
attrs[i].ulValueLen = 0;
} else if (IS_ATTRIBUTE_ARRAY (attrs + i)) {
rv = proto_read_attribute_buffer_array (msg, &array, &n_array);
if (rv != CKR_OK)
return rv;
assert (n_array * sizeof (CK_ATTRIBUTE) <= value);
if (ULONG_MAX / n_array < sizeof (CK_ATTRIBUTE) ||
length < n_array * sizeof (CK_ATTRIBUTE))
return PARSE_ERROR;
attrs[i].pValue = array;
attrs[i].ulValueLen = n_array * sizeof (CK_ATTRIBUTE);
} else {
attrs[i].pValue = p11_rpc_message_alloc_extra (msg, value);
attrs[i].pValue = p11_rpc_message_alloc_extra (msg, length);
if (!attrs[i].pValue)
return CKR_DEVICE_MEMORY;
attrs[i].ulValueLen = value;
attrs[i].ulValueLen = length;
}
}

Expand Down

0 comments on commit c7f12e2

Please sign in to comment.