pmb.parse.kconfig.check: fix writing to list arg

Python passes all arguments by reference. For mutable objects such as
a list used here, changing the object will change the original one. If
components_list is not set, this means the default value gets modified.

This lead to kernels getting checked with the wrong required components.
For example, when checking a kernel from community first with the
default component_list, it would get extended with all options needed
for a kernel in community. When checking another kernel from the
testing category, also with the default component_list, it would now
check for the community options in the testing kernel.

Related: https://stackoverflow.com/a/986145
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230402124338.64886-1-ollieparanoid@postmarketos.org%3E
This commit is contained in:
Oliver Smith 2023-04-02 14:43:39 +02:00
parent 3113f354b8
commit 89cbae6d31
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 4 additions and 0 deletions

View File

@ -237,6 +237,10 @@ def check(args, pkgname, components_list=[], details=False, must_exist=True):
:returns: True when the check was successful, False otherwise
None if the aport cannot be found (only if must_exist=False)
"""
# Don't modify the original component_list (arguments are passed as
# reference, a list is not immutable)
components_list = components_list.copy()
# Pkgname: allow omitting "linux-" prefix
if pkgname.startswith("linux-"):
flavor = pkgname.split("linux-")[1]