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

Wrong parameter parsing #2224

Closed
luis4a0 opened this issue Sep 7, 2021 · 7 comments · Fixed by #2226
Closed

Wrong parameter parsing #2224

luis4a0 opened this issue Sep 7, 2021 · 7 comments · Fixed by #2226
Assignees
Labels
Milestone

Comments

@luis4a0
Copy link
Contributor

luis4a0 commented Sep 7, 2021

Describe the bug
Issuing multipass launch -n asdf -mem 2048M gives

launch failed: '2048M' is not a supported alias. Please use `multipass find` for supported image aliases.

Expected behavior
-mem should be recognized as a wrong parameter, before checking the validity of 2048M as an alias.

@luis4a0 luis4a0 added the bug label Sep 7, 2021
@townsend2010
Copy link
Contributor

Hey @luis4a0,

Thanks for entering this. For the expected behavior, I'm not sure if this is what you meant, but -mem itself is itself a valid option (the -m part of it is the option), it's just that em is not a valid memory size and that is what needs to be validated. Same goes for all other options.

For example, it's possible someone may enter -cpus and that would be parsed as -c with pus being the number of CPUs given at launch.

@luis4a0
Copy link
Contributor Author

luis4a0 commented Sep 7, 2021

The fact that -mem is a valid option escaped me. Thanks for pointing this out!

Now I see it's not a trivial fix. We need to parse in two stages (analogous to lex and yacc): first we generate tokens from all the options in the command line (that is, one for each unit separated by spaces) and then we parse the those tokens, combined in the order given. Maybe there is a simpler way to do it, I'll think about it.

@townsend2010
Copy link
Contributor

Hey @luis4a0, ok, cool.

It should actually be quite trivial to fix. In validate_create_arguments(), instead of calling validate_image() early, call it after all of the other options have been validated. 😉

@ricab
Copy link
Collaborator

ricab commented Sep 7, 2021

Perhaps this could be dealt with in the client: confirm it is a valid MemorySize before adding it to the request. That's already done for CPUs.

@luis4a0 luis4a0 self-assigned this Sep 7, 2021
@luis4a0
Copy link
Contributor Author

luis4a0 commented Sep 7, 2021

Thanks for your insights @townsend2010 and @ricab! I implemented the latter, it proved to be easier. In fact, I didn't remove check code for the daemon because it is still needed to check that the requested size is bigger than the minimum.

@Saviq
Copy link
Collaborator

Saviq commented Sep 7, 2021

I didn't remove check code for the daemon

You also can't trust the client to have done the validation :)

@ricab
Copy link
Collaborator

ricab commented Sep 8, 2021

I didn't remove check code for the daemon

You also can't trust the client to have done the validation :)

Yep, the daemon of course needs to validate the contents of RPC requests (to be sure, I did not mean to suggest otherwise).

bors bot added a commit that referenced this issue Sep 16, 2021
2226: Parse memory, disk parameters in the client. r=ricab a=luis4a0

Fixes #2224.

Co-authored-by: Luis Peñaranda <luis.penaranda@canonical.com>
bors bot added a commit that referenced this issue Sep 16, 2021
2226: Parse memory, disk parameters in the client. r=ricab a=luis4a0

Fixes #2224.

Co-authored-by: Luis Peñaranda <luis.penaranda@canonical.com>
bors bot added a commit that referenced this issue Sep 16, 2021
2226: Parse memory, disk parameters in the client. r=ricab a=luis4a0

Fixes #2224.

Co-authored-by: Luis Peñaranda <luis.penaranda@canonical.com>
@bors bors bot closed this as completed in ff3d2cd Sep 17, 2021
@Saviq Saviq added this to the v1.8.0 milestone Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants