From 7cefc5fe35a514637b1b0b68e044f0de0d188e22 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Wed, 5 Oct 2022 03:45:22 +0200 Subject: [PATCH 2/2] mockbuild: escape rpm command under mock Arguments of the 'rpm' part after 'mock --shell' needs to be escaped. Example: mock -r xxx --chroot ... --shell rpm --define '_sourcedir xxx' ... JIRA: RHELCMP-10150 Resolves: rhbz#2130349 Signed-off-by: Ondrej Nosek --- pyrpkg/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index a40fa5a..1595344 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -22,6 +22,7 @@ import os import posixpath import random import re +import shlex import shutil import subprocess import sys @@ -43,13 +44,14 @@ from six.moves.urllib.parse import urljoin from pyrpkg import layout from pyrpkg.errors import (AlreadyUploadedError, HashtypeMixingError, - UnknownTargetError, rpkgAuthError, rpkgError, NoSourcesError) + NoSourcesError, UnknownTargetError, rpkgAuthError, + rpkgError) from pyrpkg.lookaside import CGILookasideCache from pyrpkg.sources import SourcesFile from pyrpkg.spec import SpecFile from pyrpkg.utils import (cached_property, extract_srpm, find_me, is_file_tracked, is_lookaside_eligible_file, - spec_file_processed_by_rpmautospec, log_result) + log_result, spec_file_processed_by_rpmautospec) from .gitignore import GitIgnore @@ -813,6 +815,8 @@ class Commands(object): # listing for each subpackage. We only care about the first. rpm_cmd.extend(["-q", "--qf", "??%{NAME} %{EPOCH} %{VERSION} %{RELEASE}??", "--specfile", "%s" % os.path.join(tmp_root, self.spec)]) + # escape whole 'rpm' command because it will be executed under mock command + rpm_cmd = [shlex.quote(item) for item in rpm_cmd] main_cmd = cmd + ['--shell'] + rpm_cmd \ + ['> ' + os.path.join(tmp_root, 'output')] -- 2.37.3