-
Notifications
You must be signed in to change notification settings - Fork 531
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
Quote input strings before constructing a command line #1098
Conversation
Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
We need some description for this PR #Resolved |
I still can execute commands even with quotes #ByDesign |
Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
because system() and popen() will use `sh` internally and `sh` is symlink of `dash` on Debian
static inline std::string shellquote(const std::string& str) | ||
{ | ||
static const std::regex re("([$`\"\\\n])"); | ||
return "\"" + std::regex_replace(str, re, "\\$1") + "\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we be sure this regex is enough for everything?
Should we better create functions to check the input parameters and run them?
Our input parameters types are easy:
- ip address
- network mask
- network device
- number
- string enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the PR comment at the top with answer.
I agree case-by-case protection is also possible, this one is for general purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
@qiluo-msft in the api removeHostVlanMember, is the cmds having cmds as input instead of inner? or is this expected ?
|
Quote input strings from function arguments before constructing a command line, so prevent of the bash script input injection.
man dash
shows below section, which indicates the double quotes and escaping is enough for general use.