14
0
Files
python-python-rpm-spec/avoid-DoS-on-carefully-crafted-spec-files.patch

31 lines
1.0 KiB
Diff
Raw Normal View History

diff --git a/pyrpm/spec.py b/pyrpm/spec.py
index 42515bf..1a290ba 100644
--- a/pyrpm/spec.py
+++ b/pyrpm/spec.py
@@ -490,7 +490,7 @@ def from_string(cls, string: str) -> "Spec":
return spec
-def replace_macros(string: str, spec: Spec) -> str:
+def replace_macros(string: str, spec: Spec, max_attempts: int = 1000) -> str:
"""Replace all macros in given string with corresponding values.
For example, a string '%{name}-%{version}.tar.gz' will be transformed to 'foo-2.0.tar.gz'.
@@ -555,9 +555,13 @@ def get_replacement_string(match: re.Match) -> str:
# Recursively expand macros
# Note: If macros are not defined in the spec file, this won't try to
# expand them.
- while True:
+ attempt = 0
+ ret = ""
+ while attempt < max_attempts:
+ attempt += 1
ret = re.sub(_macro_pattern, get_replacement_string, string)
if ret != string:
string = ret
continue
- return ret
+ break
+ return ret
\ No newline at end of file