From 0c0ebc1fdf57c3ac968e1afdadbc17b9010da6fa Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 7 Dec 2013 07:09:41 -0600 Subject: [PATCH] remote-helpers: add extra safety checks Suggested-by: Roman Ovchinnikov Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-bzr | 14 ++++++++++---- contrib/remote-helpers/git-remote-hg | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr index 7e345320ad..332aba784b 100755 --- a/contrib/remote-helpers/git-remote-bzr +++ b/contrib/remote-helpers/git-remote-bzr @@ -883,6 +883,16 @@ def main(args): global branches, peers global transports + marks = None + is_tmp = False + gitdir = os.environ.get('GIT_DIR', None) + + if len(args) < 3: + die('Not enough arguments.') + + if not gitdir: + die('GIT_DIR not set') + alias = args[1] url = args[2] @@ -891,7 +901,6 @@ def main(args): blob_marks = {} parsed_refs = {} files_cache = {} - marks = None branches = {} peers = {} transports = [] @@ -899,11 +908,8 @@ def main(args): if alias[5:] == url: is_tmp = True alias = hashlib.sha1(alias).hexdigest() - else: - is_tmp = False prefix = 'refs/bzr/%s' % alias - gitdir = os.environ['GIT_DIR'] dirname = os.path.join(gitdir, 'bzr', alias) if not is_tmp: diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 3cd964dd2d..852fdcf517 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -1164,6 +1164,16 @@ def main(args): global dry_run global notes, alias + marks = None + is_tmp = False + gitdir = os.environ.get('GIT_DIR', None) + + if len(args) < 3: + die('Not enough arguments.') + + if not gitdir: + die('GIT_DIR not set') + alias = args[1] url = args[2] peer = None @@ -1184,16 +1194,12 @@ def main(args): if alias[4:] == url: is_tmp = True alias = hashlib.sha1(alias).hexdigest() - else: - is_tmp = False - gitdir = os.environ['GIT_DIR'] dirname = os.path.join(gitdir, 'hg', alias) branches = {} bmarks = {} blob_marks = {} parsed_refs = {} - marks = None parsed_tags = {} filenodes = {} fake_bmark = None