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

CLI parsing accepts short commands #54

Open
dajtxx opened this issue Aug 17, 2023 · 1 comment
Open

CLI parsing accepts short commands #54

dajtxx opened this issue Aug 17, 2023 · 1 comment
Assignees
Labels
bug Something isn't working firmware Issues and enhancements related to firmware development.

Comments

@dajtxx
Copy link
Contributor

dajtxx commented Aug 17, 2023

For example mqtt log will execute as mqtt login, and mqtt logo will run mqtt logout.

See this line

The string comparison only goes as far as the input string.

@dajtxx dajtxx added bug Something isn't working firmware Issues and enhancements related to firmware development. labels Aug 17, 2023
@kebab01 kebab01 self-assigned this Aug 24, 2023
@kebab01
Copy link
Contributor

kebab01 commented Aug 24, 2023

The issue is in the way we are using the strncmp function. Take the following example from the ftp cli:

if (!strncmp("login", param, paramLen)) {
            ...
}

if the user types ftp lo, this will match against ftp login as paramLen will be the length of the parameter the user typed in and not the length of the command we want to match against. This means that strncmp will compare lo against the first 2 characters of login, successfully matching.

The following change fixes this:

if (!strncmp("login", param, strlen("login"))) {
            ...
}

kebab01 added a commit that referenced this issue Aug 24, 2023
Changed the strncmp functions to check against the length of the command we wish to match against
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working firmware Issues and enhancements related to firmware development.
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants