chgserver: check type passed to S channel
authorJun Wu <quark@fb.com>
Fri, 06 Jan 2017 16:12:25 +0000
changeset 30727 18eb63ec8475
parent 30726 dd897eb1699e
child 30728 7438cb35979a
chgserver: check type passed to S channel It currently only supports the "system" type. Add an explicit check.
mercurial/chgserver.py
--- a/mercurial/chgserver.py	Fri Jan 06 16:11:03 2017 +0000
+++ b/mercurial/chgserver.py	Fri Jan 06 16:12:25 2017 +0000
@@ -312,12 +312,15 @@
         self.out.write(data)
         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 = [
     # server.ch, ui.fp, mode