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

add general check for yaml on rcl_yaml_param_parser #809

Merged
merged 14 commits into from Oct 19, 2020

Conversation

iuhilnehc-ynos
Copy link
Collaborator

@iuhilnehc-ynos iuhilnehc-ynos commented Sep 22, 2020

Fixes #301

Signed-off-by: Chen Lihui Lihui.Chen@sony.com

Updated: Besides fixing to not allow '//' in node name, adding the general check and some special rules about wildcards(including some new rules on ros2/design#303)

/// Validate a name whether it is a valid namespace
///
static rcutils_ret_t
__validate_namespace(const char * name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why it should not be dependent on rmw? could you elaborate a little bit? I think it would be better to use rmw to validate the namespace instead of having redundant code else where.

I found that using rmw_validate_namespace has some limitations because there are some extra rules, such as "/**" (maybe more in the future), need to be parsed.

you mean ros2/rclcpp#1265?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for your questions, @fujitatomoya

why it should not be dependent on rmw?

"/**" is a special rule at rclcpp, it is invalid checked by rmw_validate_namespace.
If using rmw_validate_namespace, we need to add more extra checking for these special rules inside __validate_namespace, which seems not a requirement of this issue.

maybe more in the future

you mean ros2/rclcpp#1265?

Yes.

Copy link
Member

Choose a reason for hiding this comment

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

Though this solves the reported issue, I think we should do a more general check if the node namespace (and node name) are valid. I would do this using rmw_validate_namespace and rmw_validate_node_name, and handle the special cases for wildcards * and **.

I suggest implementing this function as follows:

  1. Make a copy of the name to validate
  2. Substitute substrings * and ** with arbitrary valid strings (e.g. WILDCARD)
  3. Pass the modified name to rmw_validate_namespace

By using the rmw functions we are consistent with what it means to be a valid name.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jacobperron

I suggest implementing this function as follows

Thanks for your suggestion. I'll update it later.

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

I think we should also validate the node name. If you don't want to add it to this PR, we do it in a follow-up.

/// Validate a name whether it is a valid namespace
///
static rcutils_ret_t
__validate_namespace(const char * name)
Copy link
Member

Choose a reason for hiding this comment

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

Though this solves the reported issue, I think we should do a more general check if the node namespace (and node name) are valid. I would do this using rmw_validate_namespace and rmw_validate_node_name, and handle the special cases for wildcards * and **.

I suggest implementing this function as follows:

  1. Make a copy of the name to validate
  2. Substitute substrings * and ** with arbitrary valid strings (e.g. WILDCARD)
  3. Pass the modified name to rmw_validate_namespace

By using the rmw functions we are consistent with what it means to be a valid name.

What do you think?

Chen Lihui added 6 commits October 12, 2020 11:08
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
This reverts commit b847544.

Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
This reverts commit 52bb028.

Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
@iuhilnehc-ynos
Copy link
Collaborator Author

iuhilnehc-ynos commented Oct 12, 2020

@jacobperron

After rebasing from master, I need to force push these commits to this branch.
Could you please help review it again?

BTW: I didn't add some extra rules which are not merged (such as ros2/rclcpp#1265) in this PR

@iuhilnehc-ynos iuhilnehc-ynos changed the title Fix for allowing '//' in node name Fix to not allow '//' in node name Oct 12, 2020
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

LGTM.

Could you also add a test for the /** case? Thanks!

rcl_yaml_param_parser/src/parse.c Outdated Show resolved Hide resolved
Chen Lihui added 3 commits October 13, 2020 10:00
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
@iuhilnehc-ynos
Copy link
Collaborator Author

@jacobperron

Could you also add a test for the /** case? Thanks!

I have added the test and added additional rules for wildcards based on ros2/design#303.
Could you review it again?

@iuhilnehc-ynos iuhilnehc-ynos changed the title Fix to not allow '//' in node name add general check for yaml on rcl_yaml_param_parser Oct 13, 2020
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
…partial matches

Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
@iuhilnehc-ynos
Copy link
Collaborator Author

The rcl_yaml_param_parser.cppcheck.error: syntaxError (src/parse.c:478) on macOS confused me, I'll rebuild it on my local environment tommorow because I have no environment now.

@iuhilnehc-ynos
Copy link
Collaborator Author

@ros-pull-request-builder retest this please

@jacobperron
Copy link
Member

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

I'm not sure about the cppcheck failure on macOS or the Windows build failure 🤔

rcl_yaml_param_parser/src/parse.c Show resolved Hide resolved
/// \return RCUTILS_RET_ERROR if an unspecified error occurred.
RCL_YAML_PARAM_PARSER_LOCAL
rcutils_ret_t
__validate_namespace(const char * namespace);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use a single underscore. Double underscores are reserved identifiers.

Suggested change
__validate_namespace(const char * namespace);
_validate_namespace(const char * namespace);

Same for other functions names below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's good to know.

@iuhilnehc-ynos
Copy link
Collaborator Author

cppcheck failure on macOS

the version of cppcheck on macOS is 1.89, so I should not use 'namespace' as a variable name which is a keyword in C++.

Co-authored-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Chen Lihui <Lihui.Chen@sony.com>
@jacobperron
Copy link
Member

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for iterating!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rcl_yaml_param_parser allows two // in node name
3 participants