Skip to content

Commit

Permalink
rpc: check value length before reading the value
Browse files Browse the repository at this point in the history
Signed-off-by: Zoltan Fridrich <zfridric@redhat.com>
  • Loading branch information
ZoltanFridrich committed Mar 14, 2024
1 parent ebfc19c commit f53bdc2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions p11-kit/rpc-message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ p11_rpc_message_get_attribute (p11_rpc_message *msg,
{
uint32_t type, length;
CK_ULONG decode_length;
size_t saved_offset;
unsigned char validity;
p11_rpc_attribute_serializer *serializer;
p11_rpc_value_type value_type;
Expand Down Expand Up @@ -1364,15 +1365,26 @@ p11_rpc_message_get_attribute (p11_rpc_message *msg,
return false;
}

/* Decode the attribute value */
value_type = map_attribute_to_value_type (type);
assert (value_type < ELEMS (p11_rpc_attribute_serializers));
serializer = &p11_rpc_attribute_serializers[value_type];
assert (serializer != NULL);
if (!serializer->decode (msg, buffer, offset, attr->pValue, &decode_length))
return false;
if (attr->pValue == NULL && length != 0 && decode_length > length)

/* Get the attribute value length */
saved_offset = *offset;
if (!serializer->decode (NULL, buffer, offset, NULL, &decode_length))
return false;

/* Decode the attribute value */
if (attr->pValue != NULL) {
if (length < decode_length)
return false;

*offset = saved_offset;
if (!serializer->decode (msg, buffer, offset, attr->pValue, NULL))
return false;
}

attr->type = type;
attr->ulValueLen = length;
return true;
Expand Down

0 comments on commit f53bdc2

Please sign in to comment.