Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: check value length before writing the value #629

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading