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

begin_node does not enforce limits defined in the specification #32

Closed
andreeaflorescu opened this issue Aug 23, 2021 · 2 comments · Fixed by #33
Closed

begin_node does not enforce limits defined in the specification #32

andreeaflorescu opened this issue Aug 23, 2021 · 2 comments · Fixed by #33

Comments

@andreeaflorescu
Copy link
Member

The FDT specification describes a string length of e.g. the begin_node of 1 to 31 chars and enforces a strict character limitation described in https://devicetree-specification.readthedocs.io/en/stable/devicetree-basics.html#node-name-requirements.

Enforcing the character limitation would mean adding a dependency on regex, which is undesirable. We could instead enforce the size limitation, and document the character limitation as something that is not currently validated.

@danielverkamp what do you think?

@danielverkamp
Copy link
Collaborator

I think we can check the valid chars without adding a regex dependency - it's a little verbose, but something like this should work:

const NODE_NAME_MAX_CHARS: usize = 31;
const NODE_NAME_VALID_CHARS: &str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,._+-";

fn name_ok(name: &str) -> bool {
    if name.is_empty() || name.len() > NODE_NAME_MAX_CHARS {
        return false;
    }
    !name.contains(|c: char| !NODE_NAME_VALID_CHARS.contains(c))
}

I can put together a PR if you think this approach looks OK.

danielverkamp added a commit to danielverkamp/vm-fdt that referenced this issue Aug 23, 2021
Add checks for the requirements in the devicetree specifications.

This does not check for any specific bus binding requirements for unit
addresses (as in "node-name@unit-address"); only the generic
requirements for all node names are enforced.

Fixes rust-vmm#32.

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
@danielverkamp
Copy link
Collaborator

I tweaked the checks some more using matches and added some checks for the @unit-address part in node names.

danielverkamp added a commit to danielverkamp/vm-fdt that referenced this issue Aug 23, 2021
Add checks for the requirements in the devicetree specifications.

This does not check for any specific bus binding requirements for unit
addresses (as in "node-name@unit-address"); only the generic
requirements for all node names are enforced.

Fixes rust-vmm#32.

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
danielverkamp added a commit to danielverkamp/vm-fdt that referenced this issue Aug 24, 2021
Add checks for the requirements in the devicetree specifications.

This does not check for any specific bus binding requirements for unit
addresses (as in "node-name@unit-address"); only the generic
requirements for all node names are enforced.

Fixes rust-vmm#32.

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
lauralt pushed a commit that referenced this issue Aug 25, 2021
Add checks for the requirements in the devicetree specifications.

This does not check for any specific bus binding requirements for unit
addresses (as in "node-name@unit-address"); only the generic
requirements for all node names are enforced.

Fixes #32.

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
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 a pull request may close this issue.

2 participants