Repository navigation
Apply suggested fix to UXTU4Unix/UXTU4Unix.py from Copilot Autofix #20
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
Changes from all commits
6bb4cf4
81bce12
4dcbb3c
a009268
9477c0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import plistlib | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import shlex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from configparser import ConfigParser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LOCAL_VERSION = "0.4.2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -60,10 +61,23 @@ def clear(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_hardware_info(command, use_sudo=False): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password = cfg.get('User', 'Password', fallback='') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command_args = shlex.split(command) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if use_sudo: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command = f"echo '{password}' | sudo -S {command}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output, error = process.communicate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process = subprocess.Popen( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ['sudo', '-S'] + command_args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdin=subprocess.PIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout=subprocess.PIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stderr=subprocess.PIPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output, error = process.communicate(input=(password + '\n').encode('utf-8')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process = subprocess.Popen( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command_args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdin=subprocess.PIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout=subprocess.PIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stderr=subprocess.PIPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output, error = process.communicate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
65
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: stdin is piped even when no input is sent for the non-sudo path; consider dropping In the non-sudo branch of audit_process = subprocess.Popen(
command_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
output, error = audit_process.communicate()
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return output.decode('utf-8').strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_codename(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -265,8 +279,13 @@ def welcome_tutorial(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while True: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run("sudo -k", shell=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password = getpass.getpass("Enter your sudo (login) password: ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo_check_command = f"echo '{password}' | sudo -S ls /" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo_check_process = subprocess.run(sudo_check_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo_check_process = subprocess.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ["sudo", "-S", "ls", "/"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input=password + "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout=subprocess.PIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stderr=subprocess.PIPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if sudo_check_process.returncode == 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -491,10 +510,14 @@ def pass_cfg(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| choice = input("Option: ").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if choice == "1": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while True: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run("sudo -k", shell=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run(["sudo", "-k"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| password = getpass.getpass("Enter your sudo (login) password: ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo_check_command = f"echo '{password}' | sudo -S ls /" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo_check_process = subprocess.run(sudo_check_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo_check_process = subprocess.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ["sudo", "-S", "-k", "ls", "/"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input=(password + "\n").encode(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout=subprocess.PIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stderr=subprocess.PIPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if sudo_check_process.returncode == 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cfg.set('User', 'Password', password) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with open(CONFIG_PATH, 'w') as config_file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -686,7 +709,7 @@ def install_manual(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prompt_restart() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def prompt_restart(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| choice = input("Do you want to restart your computer to take effects? (y/n)").lower() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| choice = input("Do you want to restart your computer to take effect? (y/n)").lower() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if choice == "y": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input("Save your current work before restarting. Press Enter to continue") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| restart_command = '''osascript -e 'tell app "System Events" to restart' ''' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
question: Consider whether
shlex.splitis appropriate ifcommandmay rely on shell features like pipes or redirection.If callers may currently pass shell operators (pipes, redirects, globbing, etc.), this change will alter or break those commands. Please either (a) guarantee and document that
commandis always a simple executable plus args, or (b) support both list and string inputs and handle shell-operator use cases explicitly.