Qemu_utils Preperation/Tests Module#4325
Qemu_utils Preperation/Tests Module#4325YongxueHong wants to merge 2 commits intoavocado-framework:masterfrom
Conversation
Summary of ChangesHello @YongxueHong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness and maintainability of the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly improves the qemu_utils module by introducing comprehensive unit and functional tests, enhancing its robustness and reliability, and improving maintainability through updated docstrings and modern f-string formatting. However, it maintains and introduces security risks by using string interpolation for shell commands. Specifically, the has_option and get_support_machine_type functions are vulnerable to command injection if provided paths are maliciously crafted or contain shell metacharacters. These functions should be refactored to use list-based arguments for process execution to ensure safe handling of command-line parameters.
| hlp = process.run( | ||
| "%s -help" % qemu_path, shell=True, ignore_status=True, verbose=False | ||
| f"{qemu_path} -help", shell=True, ignore_status=True, verbose=False | ||
| ).stdout_text |
There was a problem hiding this comment.
The qemu_path parameter is interpolated directly into a command string executed with shell=True. This allows for arbitrary command injection if the path contains shell metacharacters or is maliciously crafted. For example, a path like /usr/bin/qemu; id would execute the id command. To remediate this, pass the command and its arguments as a list and set shell=False.
| hlp = process.run( | |
| "%s -help" % qemu_path, shell=True, ignore_status=True, verbose=False | |
| f"{qemu_path} -help", shell=True, ignore_status=True, verbose=False | |
| ).stdout_text | |
| hlp = process.run( | |
| [qemu_path, "-help"], shell=False, ignore_status=True, verbose=False | |
| ).stdout_text |
| :rtype: Tuple[List, List, List] | ||
| """ | ||
| o = process.run("%s -M ?" % qemu_binary).stdout_text.splitlines() | ||
| o = process.run(f"{qemu_binary} -M ?").stdout_text.splitlines() |
There was a problem hiding this comment.
The qemu_binary parameter is interpolated into a command string. This is vulnerable to command injection if process.run uses a shell, or argument injection if the path contains spaces. It is safer to pass the command as a list of arguments and avoid string interpolation for command construction.
| o = process.run(f"{qemu_binary} -M ?").stdout_text.splitlines() | |
| o = process.run([qemu_binary, "-M", "?"]).stdout_text.splitlines() |
b844690 to
ba462d8
Compare
richtja
left a comment
There was a problem hiding this comment.
Hi @YongxueHong, thanks a lot for preparing qemu_utils for migration. Overall it LGTM I have just one question related to pylint check.
| useless-suppression, | ||
| use-symbolic-message-instead, | ||
| too-few-public-methods, | ||
| E0401, |
There was a problem hiding this comment.
can you please tell me, because of what you got the import error? IIUIC this is valid check and shouldn't get it normally.
There was a problem hiding this comment.
Hi @richtja
Yeah, I thought it should not be here, but I met a CI failure about "Unable to import process from avocado.utils" for from avocado.utils import process before, I am not sure what happened with the environment of CI, so here I did this workaround to disable this pylint checker.
I could remove it right now and then have a look if it can be passed.
Thanks.
There was a problem hiding this comment.
Hi @richtja
I pushed the PR without the E0401 pylint checker, but it failed in CI checkers. Thanks.
pylint...................................................................Failed
- hook id: pylint
- exit code: 1
Found configuration file: static-checks/../avocado-static-checks.conf
** Running pylint on directory 'virttest' with config from '.pylintrc_utils'...
************* Module avocado-vt.virttest.vt_utils.qemu_utils
virttest/vt_utils/qemu_utils.py:27:0: E0401: Unable to import 'avocado.utils' (import-error)
There was a problem hiding this comment.
I see, let me look into that.
ba462d8 to
14396e7
Compare
- Fix docstring formatting by removing empty first lines - Add missing type documentation for qemu_path parameter - Convert % string formatting to f-strings for better readability - Improve module docstring to provide clearer functionality overview - Remove from .pylintrc_utils ignore list to enable pylint checking Signed-off-by: Yongxue Hong <yhong@redhat.com>
This commit introduces both unit and functional tests for the qemu_utils module, providing thorough coverage of QEMU option detection and machine type querying functionality. Signed-off-by: Yongxue Hong <yhong@redhat.com>
14396e7 to
0de16ef
Compare
Improvement of the qemu_utils module and add the Functional/Unit tests for the migration of aautils.
ID: LNXVASTACA-301