Skip to content

Commit 82a46c6

Browse files
authored
Fix shell injection in user_set_shell and chown (#4443)
Use argv list with run() instead of sh -c with f-string interpolation, fix mutable default argument in chown, add debug logging on failure.
1 parent 86dc1bb commit 82a46c6

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

archinstall/lib/installer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,18 +1964,22 @@ def set_user_password(self, user: User) -> bool:
19641964
def user_set_shell(self, user: str, shell: str) -> bool:
19651965
info(f'Setting shell for {user} to {shell}')
19661966

1967+
cmd = ['arch-chroot', '-S', str(self.target), 'chsh', '-s', shell, user]
19671968
try:
1968-
self.arch_chroot(f'sh -c "chsh -s {shell} {user}"')
1969+
run(cmd)
19691970
return True
1970-
except SysCallError:
1971+
except CalledProcessError as err:
1972+
debug(f'Error setting user shell: {err}')
19711973
return False
19721974

1973-
def chown(self, owner: str, path: str, options: list[str] = []) -> bool:
1974-
cleaned_path = path.replace("'", "\\'")
1975+
def chown(self, owner: str, path: str, options: list[str] | None = None) -> bool:
1976+
options = options or []
1977+
cmd = ['arch-chroot', '-S', str(self.target), 'chown', *options, owner, path]
19751978
try:
1976-
self.arch_chroot(f"sh -c 'chown {' '.join(options)} {owner} {cleaned_path}'")
1979+
run(cmd)
19771980
return True
1978-
except SysCallError:
1981+
except CalledProcessError as err:
1982+
debug(f'Error changing ownership of {path}: {err}')
19791983
return False
19801984

19811985
def set_vconsole(self, locale_config: LocaleConfiguration) -> None:

0 commit comments

Comments
 (0)