Patchwork [STABLE] debugssl: convert port number to int (issue5757)

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 14, 2017, 1:21 p.m.
Message ID <88572b7e50fd5f0e8632.1513257698@mimosa>
Download mbox | patch
Permalink /patch/26276/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 14, 2017, 1:21 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1513256866 -32400
#      Thu Dec 14 22:07:46 2017 +0900
# Branch stable
# Node ID 88572b7e50fd5f0e86329943795f6a3e38a2ec31
# Parent  7b73bf1a48d430986e8561db9070634c1923df70
debugssl: convert port number to int (issue5757)

It doesn't use util.getport(), which may resolve service name to port number.
Augie Fackler - Dec. 15, 2017, 11:24 p.m.
On Thu, Dec 14, 2017 at 10:21:38PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1513256866 -32400
> #      Thu Dec 14 22:07:46 2017 +0900
> # Branch stable
> # Node ID 88572b7e50fd5f0e86329943795f6a3e38a2ec31
> # Parent  7b73bf1a48d430986e8561db9070634c1923df70
> debugssl: convert port number to int (issue5757)

queued for stable, thanks

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2086,10 +2086,12 @@  def debugssl(ui, repo, source=None, **op
     url = util.url(source)
     addr = None
 
-    if url.scheme == 'https':
-        addr = (url.host, url.port or 443)
-    elif url.scheme == 'ssh':
-        addr = (url.host, url.port or 22)
+    defaultport = {'https': 443, 'ssh': 22}
+    if url.scheme in defaultport:
+        try:
+            addr = (url.host, int(url.port or defaultport[url.scheme]))
+        except ValueError:
+            raise error.Abort(_("malformed port number in URL"))
     else:
         raise error.Abort(_("only https and ssh connections are supported"))