]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build.py: Fix shell escape.
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Thu, 24 Jul 2014 00:38:55 +0000 (02:38 +0200)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Thu, 24 Jul 2014 00:38:55 +0000 (02:38 +0200)
debian_build.py
lib/sbuild.py

index f1398dd50fba764e9601fc33aab5ef022b6fabbd..52935fb4cf4bc66bd9cdd20e3ece83d5cf6f75ad 100755 (executable)
@@ -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)
index 4a2674b13527820685a3a03691dffe998e063106..b63729f0e7edf355714abc0c143638a20a98c274 100644 (file)
@@ -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