git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] remote-helpers: add extra safety checks

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Dec 7, 2013, 13:09 UTC
Message-ID
<1386421783-27781-3-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1386421783-27781-1-git-send-email-felipe.contreras@gmail.com>
Suggested-by: Roman Ovchinnikov <coolthecold@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 054161a..858ba3c 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -884,6 +884,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]
 
@@ -892,7 +902,6 @@ def main(args):
     blob_marks = {}
     parsed_refs = {}
     files_cache = {}
-    marks = None
     branches = {}
     peers = {}
     transports = []
@@ -900,11 +909,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 a81d59e..aa1d230 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -1165,6 +1165,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
@@ -1185,16 +1195,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
-- 
1.8.4.2+fc1
Previous: Felipe ContrerasNext: Felipe Contreras
Message 3 of 8 in “remote-helpers: fixes”
  1. 0/4 remote-helpers: fixesFelipe Contreras, Dec 7, 2013
  2. 1/4 remote-hg: avoid buggy strftime()Felipe Contreras, Dec 7, 2013
  3. 2/4 remote-helpers: add extra safety checksFelipe Contreras, Dec 7, 2013
  4. 3/4 remote-hg: fix 'shared path' pathFelipe Contreras, Dec 7, 2013
  5. Antoine PelisseDec 13, 2013
  6. Junio C HamanoDec 17, 2013
  7. remote-hg: test 'shared_path' in a moved cloneAntoine Pelisse, Dec 23, 2013
  8. 4/4 remote-hg: add tests for special filenamesFelipe Contreras, Dec 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.