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

core: memory exhaustion bug fix #45

Merged
merged 1 commit into from
Nov 14, 2023
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
19 changes: 18 additions & 1 deletion include/ctraces/ctr_variant_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#include <mpack/mpack.h>

#define CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE 100
#define CFL_VARIANT_UTILS_INITIAL_ARRAY_SIZE 100
#define CFL_VARIANT_UTILS_SERIALIZED_ARRAY_SIZE_LIMIT 100000

/* These are the only functions meant for general use,
* the reason why the kvlist packing and unpacking
* functions are exposed is the internal and external
Expand Down Expand Up @@ -226,12 +230,25 @@ static inline int unpack_cfl_array(mpack_reader_t *reader,

entry_count = mpack_tag_array_count(&tag);

internal_array = cfl_array_create(entry_count);
if (entry_count >= CFL_VARIANT_UTILS_SERIALIZED_ARRAY_SIZE_LIMIT) {
return -2;
}

if (entry_count >= CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE) {
internal_array = cfl_array_create(CFL_VARIANT_UTILS_INITIAL_ARRAY_SIZE);
}
else {
internal_array = cfl_array_create(entry_count);
}

if (internal_array == NULL) {
return -3;
}

if (entry_count >= CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE) {
cfl_array_resizable(internal_array, CFL_TRUE);
}

for (index = 0 ; index < entry_count ; index++) {
result = unpack_cfl_variant(reader, &entry_value);

Expand Down
Loading