Patchwork [2,of,3] chgserver: check type passed to S channel

login
register
mail settings
Submitter Jun Wu
Date Jan. 6, 2017, 4:17 p.m.
Message ID <703fee4099efac592f6a.1483719477@x1c>
Download mbox | patch
Permalink /patch/18126/
State Accepted
Headers show

Comments

Jun Wu - Jan. 6, 2017, 4:17 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1483719145 0
#      Fri Jan 06 16:12:25 2017 +0000
# Node ID 703fee4099efac592f6ae1c48bfebf806dfd95bf
# Parent  530b32a20c085fd9819bad3235ffbca5f98095ea
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 703fee4099ef
chgserver: check type passed to S channel

It currently only supports the "system" type. Add an explicit check.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -313,10 +313,13 @@  class channeledsystem(object):
         self.out.flush()
 
-        length = self.in_.read(4)
-        length, = struct.unpack('>I', length)
-        if length != 4:
-            raise error.Abort(_('invalid response'))
-        rc, = struct.unpack('>i', self.in_.read(4))
-        return rc
+        if type == 'system':
+            length = self.in_.read(4)
+            length, = struct.unpack('>I', length)
+            if length != 4:
+                raise error.Abort(_('invalid response'))
+            rc, = struct.unpack('>i', self.in_.read(4))
+            return rc
+        else:
+            raise error.ProgrammingError('invalid S channel type: %s' % type)
 
 _iochannels = [