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

Change the delimeters to prevent possible tracebacks on some packages with dpkg_lowpkg #62519

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/62519.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix possible tracebacks if there is a package with '------' or '======' in the description is installed on the Debian based minion.
13 changes: 8 additions & 5 deletions salt/modules/dpkg_lowpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ def _get_pkg_info(*packages, **kwargs):
"origin:${Origin}\\n"
"homepage:${Homepage}\\n"
"status:${db:Status-Abbrev}\\n"
"======\\n"
"description:${Description}\\n"
"------\\n'"
"\\n*/~^\\\\*\\n'"
)
cmd += " {}".format(" ".join(packages))
cmd = cmd.strip()
Expand All @@ -287,9 +286,13 @@ def _get_pkg_info(*packages, **kwargs):
else:
return ret

for pkg_info in [elm for elm in re.split(r"------", call["stdout"]) if elm.strip()]:
for pkg_info in [
elm
for elm in re.split(r"\r?\n\*/~\^\\\*(\r?\n|)", call["stdout"])
if elm.strip()
]:
pkg_data = {}
pkg_info, pkg_descr = re.split(r"======", pkg_info)
pkg_info, pkg_descr = pkg_info.split("\ndescription:", 1)
for pkg_info_line in [
el.strip() for el in pkg_info.split(os.linesep) if el.strip()
]:
Expand All @@ -299,7 +302,7 @@ def _get_pkg_info(*packages, **kwargs):
install_date = _get_pkg_install_time(pkg_data.get("package"))
if install_date:
pkg_data["install_date"] = install_date
pkg_data["description"] = pkg_descr.split(":", 1)[-1]
pkg_data["description"] = pkg_descr
ret.append(pkg_data)

return ret
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/test_dpkg_lowpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def test_info(self):
"origin:",
"homepage:http://tiswww.case.edu/php/chet/bash/bashtop.html",
"status:ii ",
"======",
"description:GNU Bourne Again SHell",
" Bash is an sh-compatible command language interpreter that"
" executes",
Expand All @@ -307,7 +306,8 @@ def test_info(self):
" The Programmable Completion Code, by Ian Macdonald, is now"
" found in",
" the bash-completion package.",
"------",
"",
"*/~^\\*", # pylint: disable=W1401
]
),
}
Expand Down