From: Benjamin Drung Date: Thu, 24 Jul 2014 00:38:55 +0000 (+0200) Subject: debian_build.py: Fix shell escape. X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=e574a43e5b341ca9838c02433e08d76fba07c918;p=profitbricks%2Fjenkins-build-scripts.git debian_build.py: Fix shell escape. --- diff --git a/debian_build.py b/debian_build.py index f1398dd..52935fb 100755 --- a/debian_build.py +++ b/debian_build.py @@ -188,6 +188,15 @@ def version_substitution(logger, pattern, git_commit=None): return version +def escape_arg(arg): + """Shell-escape arg, if necessary. + Fairly simplistic, doesn't escape anything except whitespace. + """ + if ' ' not in arg: + return arg + return '"%s"' % arg.replace('\\', r'\\').replace('"', r'\"') + + if __name__ == '__main__': logger.debug('Start-up environment:\n\n{env}\n'.format(env=pformat(ENV))) @@ -627,8 +636,8 @@ if __name__ == '__main__': ) if ret == 0: logger.info('Current environment:\n\n{env}\n'.format(env=builder.env)) - logger.info('Start building the binary package by running ' - '"{cmd}"...\n'.format(cmd=' '.join(builder.command))) + logger.info("Start building the binary package by running '{cmd}'...\n" + .format(cmd=' '.join(escape_arg(arg) for arg in builder.command))) ret = builder.build() # .. remove last commit (the one where we added the changelog entry) diff --git a/lib/sbuild.py b/lib/sbuild.py index 4a2674b..b63729f 100644 --- a/lib/sbuild.py +++ b/lib/sbuild.py @@ -41,7 +41,7 @@ class Sbuild(object): '--arch=' + self.arch, '-d', self.dist, '-c', self.chroot - ] + ['--extra-repository="' + repo + '"' for repo in self.additional_repos] + \ + ] + ['--extra-repository=' + repo for repo in self.additional_repos] + \ [self.dsc_file] return result