Fix memory corruption when maximum number of parameters is exceeded (#456)

If the maximum number is exceeded fail with an informative error message.

Fixes #419.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This commit is contained in:
Jacob Perron 2019-06-07 14:56:05 -07:00 committed by GitHub
parent 79b3ec1052
commit ec8539b65c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 546 additions and 0 deletions

View file

@ -1129,6 +1129,15 @@ static rcl_ret_t parse_key(
}
*is_new_map = false;
}
// Guard against adding more than the maximum allowed parameters
if (params_st->params[node_idx].num_params >= MAX_NUM_PARAMS_PER_NODE) {
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Exceeded maximum allowed number of parameters for a node (%d)",
MAX_NUM_PARAMS_PER_NODE);
return RCL_RET_ERROR;
}
/// Add a parameter name into the node parameters
parameter_idx = params_st->params[node_idx].num_params;
parameter_ns = ns_tracker->parameter_ns;