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

Guard against returning NULL or empty node names #570

Merged
merged 6 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion rcl/include/rcl/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ rcl_names_and_types_fini(rcl_names_and_types_t * names_and_types);
*
* The `node_names` parameter must be allocated and zero initialized.
* `node_names` is the output for this function, and contains allocated memory.
* Note that entries in the array might contain `NULL` values.
* Use rcutils_get_zero_initialized_string_array() for initializing an empty
* rcutils_string_array_t struct.
* This `node_names` struct should therefore be passed to rcutils_string_array_fini()
Expand Down Expand Up @@ -445,6 +444,8 @@ rcl_names_and_types_fini(rcl_names_and_types_t * names_and_types);
* \return #RCL_RET_OK if the query was successful, or
* \return #RCL_RET_BAD_ALLOC if an error occurred while allocating memory, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
* \return #RCL_RET_NODE_INVALID_NAME if a node with an invalid name is detected, or
* \return #RCL_RET_NODE_INVALID_NAMESPACE if a node with an invalid namespace is detected, or
* \return #RCL_RET_ERROR if an unspecified error occurs.
*/
RCL_PUBLIC
Expand Down
25 changes: 24 additions & 1 deletion rcl/src/rcl/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,30 @@ rcl_get_node_names(
rcl_node_get_rmw_handle(node),
node_names,
node_namespaces);
return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);

if (RMW_RET_OK != rmw_ret) {
return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
}

// Check that none of the node names are NULL or empty
for (size_t i = 0u; i < node_names->size; ++i) {
jacobperron marked this conversation as resolved.
Show resolved Hide resolved
if (!node_names->data[i]) {
RCL_SET_ERROR_MSG("NULL node name returned by the RMW layer");
return RCL_RET_NODE_INVALID_NAME;
}
if (!strcmp(node_names->data[i], "")) {
RCL_SET_ERROR_MSG("empty node name returned by the RMW layer");
return RCL_RET_NODE_INVALID_NAME;
}
}
// Check that none of the node namespaces are NULL
for (size_t i = 0u; i < node_namespaces->size; ++i) {
if (!node_namespaces->data[i]) {
RCL_SET_ERROR_MSG("NULL node namespace returned by the RMW layer");
return RCL_RET_NODE_INVALID_NAMESPACE;
}
}
return RCL_RET_OK;
}

rcl_ret_t
Expand Down