Skip to content

Commit 04b74e7

Browse files
committed
mpack_utils: Handle exdeeded limits of label values and replace with "..." for exceeded characters
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent a3bc932 commit 04b74e7

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/cmt_mpack_utils.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ int cmt_mpack_consume_string_tag(mpack_reader_t *reader, cfl_sds_t *output_buffe
7878
{
7979
uint32_t string_length;
8080
mpack_tag_t tag;
81+
cfl_sds_t left_buffer;
82+
uint32_t left_length;
8183

8284
if (NULL == output_buffer) {
8385
return CMT_MPACK_INVALID_ARGUMENT_ERROR;
@@ -105,25 +107,35 @@ int cmt_mpack_consume_string_tag(mpack_reader_t *reader, cfl_sds_t *output_buffe
105107
*/
106108

107109
if (CMT_MPACK_MAX_STRING_LENGTH < string_length) {
108-
return CMT_MPACK_CORRUPT_INPUT_DATA_ERROR;
109-
}
110+
*output_buffer = cfl_sds_create_size(CMT_MPACK_MAX_STRING_LENGTH + 4);
110111

111-
*output_buffer = cfl_sds_create_size(string_length + 1);
112+
if (NULL == *output_buffer) {
113+
return CMT_MPACK_ALLOCATION_ERROR;
114+
}
112115

113-
if (NULL == *output_buffer) {
114-
return CMT_MPACK_ALLOCATION_ERROR;
115-
}
116+
left_length = string_length - CMT_MPACK_MAX_STRING_LENGTH;
117+
left_buffer = cfl_sds_create_size(left_length + 1);
118+
if (NULL == left_buffer) {
119+
return CMT_MPACK_ALLOCATION_ERROR;
120+
}
116121

117-
cfl_sds_set_len(*output_buffer, string_length);
122+
cfl_sds_set_len(*output_buffer, CMT_MPACK_MAX_STRING_LENGTH);
123+
mpack_read_cstr(reader, *output_buffer, CMT_MPACK_MAX_STRING_LENGTH + 1, CMT_MPACK_MAX_STRING_LENGTH);
124+
cfl_sds_cat_safe(output_buffer, "...", 3);
118125

119-
mpack_read_cstr(reader, *output_buffer, string_length + 1, string_length);
126+
mpack_read_cstr(reader, left_buffer, left_length + 1, left_length);
127+
cfl_sds_destroy(left_buffer);
128+
}
129+
else {
130+
*output_buffer = cfl_sds_create_size(string_length + 1);
120131

121-
if (mpack_ok != mpack_reader_error(reader)) {
122-
cfl_sds_destroy(*output_buffer);
132+
if (NULL == *output_buffer) {
133+
return CMT_MPACK_ALLOCATION_ERROR;
134+
}
123135

124-
*output_buffer = NULL;
136+
cfl_sds_set_len(*output_buffer, string_length);
125137

126-
return CMT_MPACK_ENGINE_ERROR;
138+
mpack_read_cstr(reader, *output_buffer, string_length + 1, string_length);
127139
}
128140

129141
mpack_done_str(reader);

0 commit comments

Comments
 (0)