From c59ba8f2bd76c67826daafbc55110673dc048fd3 Mon Sep 17 00:00:00 2001 From: Eyal Itkin Date: Sun, 24 Nov 2024 10:49:57 +0200 Subject: [PATCH] pkgconfig: Handle malformatted string dependencies Add missing checks for correctness of string dependency, including case for malformatted versioned dependency. Resolves #13950. Signed-off-by: Eyal Itkin --- mesonbuild/modules/pkgconfig.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 1bdf82931a94..8cea48f574ea 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -286,11 +286,20 @@ def add_version_reqs(self, name: str, version_reqs: T.Optional[T.List[str]]) -> self.version_reqs[name].update(version_reqs) def split_version_req(self, s: str) -> T.Tuple[str, T.Optional[str]]: + stripped_str = s.strip() + if not stripped_str: + raise mesonlib.MesonException(f'required dependency must not be empty, "{s}" was provided.') for op in ['>=', '<=', '!=', '==', '=', '>', '<']: - pos = s.find(op) - if pos > 0: - return s[0:pos].strip(), s[pos:].strip() - return s, None + pos = stripped_str.find(op) + if pos < 0: + continue + if pos == 0: + raise mesonlib.MesonException(f'required versioned dependency "{s}" is missing the dependency\'s name.') + stripped_str, version = stripped_str[0:pos].strip(), stripped_str[pos:].strip() + if not stripped_str: + raise mesonlib.MesonException(f'required versioned dependency "{s}" is missing the dependency\'s name.') + return stripped_str, version + return stripped_str, None def format_vreq(self, vreq: str) -> str: # vreq are '>=1.0' and pkgconfig wants '>= 1.0'