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

fix memory misuse potential in json_stream_sampler #1360

Merged
merged 1 commit into from
Mar 4, 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: 17 additions & 3 deletions ldms/src/sampler/json/json_stream_sampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,28 @@ int JSON_LIST_VALUE_setter(ldms_set_t set, ldms_mval_t list_mval,
LDMS_V_CHAR_ARRAY, 255);
break;
case JSON_DICT_VALUE:
rec_idx = -1;
if (!rec_type_name) {
rc = asprintf(&rec_type_name, "%s_record", (char *)ctxt);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tom95858 This patch covers the case that there is an error in asprintf (rc < 0) here. This case was not handled before this patch.

rec_idx = ldms_metric_by_name(set, rec_type_name);
free(rec_type_name);
if (rc >= 0) {
rec_idx = ldms_metric_by_name(set, rec_type_name);
free(rec_type_name);
rec_type_name = NULL;
} else {
LERROR("out of memory");
rc = ENOMEM;
goto err;
}
}
if (rec_idx < 0) {
LERROR("item_not_found");
rc = EINVAL;
goto err;
}
item_mval = ldms_record_alloc(set, rec_idx);
if (!item_mval) {
rc = ENOMEM;
LERROR("out of memory");
goto err;
}
rc = ldms_list_append_record(set, list_mval, item_mval);
Expand Down Expand Up @@ -993,7 +1007,7 @@ static int json_recv_cb(ldms_stream_event_t ev, void *arg)
const char *msg;
json_entity_t entity;
int rc = EINVAL;
ldms_schema_t schema;
ldms_schema_t schema = NULL;
struct json_cfg_inst *inst = arg;
json_entity_t schema_name;

Expand Down
Loading