Patchwork D11475: extensions: prevent a crash on py3 when testing a bad extension minimum

login
register
mail settings
Submitter phabricator
Date Sept. 21, 2021, 3:39 p.m.
Message ID <differential-rev-PHID-DREV-bodlvqw5ql5oe63fwtyc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49790/
State Superseded
Headers show

Comments

phabricator - Sept. 21, 2021, 3:39 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  A `None` placeholder is populated for each missing component by
  `util.versiontuple()`, which could safely be used with `>` on py2, but not py3.
  I guess there's another hole here where if the string is entirely bogus (i.e no
  numbers), it will be treated as 0.0, and always load.  But that's always been
  the case.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11475

AFFECTED FILES
  mercurial/extensions.py
  tests/test-extension.t

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1692,6 +1692,25 @@ 
   $ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
   [1]
 
+Don't explode on py3 with a bad version number
+
+  $ cat > minversion4.py << EOF
+  > from mercurial import util
+  > util.version = lambda: b'3.5'
+  > minimumhgversion = b'3'
+  > EOF
+  $ hg --config extensions.minversion=minversion4.py version -v
+  Mercurial Distributed SCM (version 3.5)
+  (see https://mercurial-scm.org for more information)
+  
+  Copyright (C) 2005-* Olivia Mackall and others (glob)
+  This is free software; see the source for copying conditions. There is NO
+  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  
+  Enabled extensions:
+  
+    minversion  external  
+
 Restore HGRCPATH
 
   $ HGRCPATH=$ORGHGRCPATH
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -224,8 +224,12 @@ 
     minver = getattr(mod, 'minimumhgversion', None)
     if minver:
         curver = util.versiontuple(n=2)
+        extmin = util.versiontuple(minver, 2)
 
-        if None in curver or util.versiontuple(minver, 2) > curver:
+        if None in extmin:
+            extmin = (extmin[0] or 0, extmin[1] or 0)
+
+        if None in curver or extmin > curver:
             msg = _(
                 b'(third party extension %s requires version %s or newer '
                 b'of Mercurial (current: %s); disabling)\n'