Skip to content

Commit

Permalink
mpack_utils: Handle exdeeded limits of label values and replace with …
Browse files Browse the repository at this point in the history
…"..." for exceeded characters

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Sep 30, 2024
1 parent a3bc932 commit bdb681f
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/cmt_mpack_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ int cmt_mpack_consume_uint_tag(mpack_reader_t *reader, uint64_t *output_buffer)
return CMT_MPACK_SUCCESS;
}


int cmt_mpack_consume_string_tag(mpack_reader_t *reader, cfl_sds_t *output_buffer)
{
uint32_t string_length;
mpack_tag_t tag;
cfl_sds_t left_buffer;
uint32_t left_length;

if (NULL == output_buffer) {
return CMT_MPACK_INVALID_ARGUMENT_ERROR;
Expand Down Expand Up @@ -105,25 +108,35 @@ int cmt_mpack_consume_string_tag(mpack_reader_t *reader, cfl_sds_t *output_buffe
*/

if (CMT_MPACK_MAX_STRING_LENGTH < string_length) {
return CMT_MPACK_CORRUPT_INPUT_DATA_ERROR;
}
*output_buffer = cfl_sds_create_size(CMT_MPACK_MAX_STRING_LENGTH + 4);

*output_buffer = cfl_sds_create_size(string_length + 1);
if (NULL == *output_buffer) {
return CMT_MPACK_ALLOCATION_ERROR;
}

if (NULL == *output_buffer) {
return CMT_MPACK_ALLOCATION_ERROR;
}
left_length = string_length - CMT_MPACK_MAX_STRING_LENGTH;
left_buffer = cfl_sds_create_size(left_length + 1);
if (NULL == left_buffer) {
return CMT_MPACK_ALLOCATION_ERROR;
}

cfl_sds_set_len(*output_buffer, string_length);
cfl_sds_set_len(*output_buffer, CMT_MPACK_MAX_STRING_LENGTH);
mpack_read_cstr(reader, *output_buffer, CMT_MPACK_MAX_STRING_LENGTH + 1, CMT_MPACK_MAX_STRING_LENGTH);
cfl_sds_cat_safe(output_buffer, "...", 3);

mpack_read_cstr(reader, *output_buffer, string_length + 1, string_length);
mpack_read_cstr(reader, left_buffer, left_length + 1, left_length);
cfl_sds_destroy(left_buffer);
}
else {
*output_buffer = cfl_sds_create_size(string_length + 1);

if (mpack_ok != mpack_reader_error(reader)) {
cfl_sds_destroy(*output_buffer);
if (NULL == *output_buffer) {
return CMT_MPACK_ALLOCATION_ERROR;
}

*output_buffer = NULL;
cfl_sds_set_len(*output_buffer, string_length);

return CMT_MPACK_ENGINE_ERROR;
mpack_read_cstr(reader, *output_buffer, string_length + 1, string_length);
}

mpack_done_str(reader);
Expand Down

0 comments on commit bdb681f

Please sign in to comment.