Commits

Anonymous committed 23fa86d

Correctly check upper versus lower case for mercurial command channels

  • Participants
  • Parent commits e1cce92

Comments (0)

Files changed (1)

File Data/FileStore/MercurialCommandServer.hs

 import Control.Exception (Exception, onException, throwIO)
 import Control.Monad (when)
 import Data.Bits (shiftL, shiftR, (.|.))
+import Data.Char (isLower, isUpper)
 import Data.FileStore.Utils (runShellCommand)
-import Data.IORef
+import Data.IORef (IORef, newIORef, readIORef, atomicModifyIORef)
 import Data.List (intercalate, isPrefixOf)
 import Data.List.Split (splitOn)
 import Data.Typeable (Typeable)
     when (buf == B.empty) $
        throwIO $ MercurialServerException "Unknown channel"
     let c = B8.head buf
-    when (c /= 'r' && c /= 'e' && c /= 'o' && c /= 'd') $
+    -- Mercurial says unknown lower case channels can be ignored, but upper case channels
+    -- must be handled.  Currently there are two upper case channels, 'I' and 'L' which
+    -- are both used for user input/output.  So error on any upper case channel.
+    when (isUpper c) $
        throwIO $ MercurialServerException $ "Unknown channel " ++ show c
     len <- hReadWord32be hout
     bdata <- B.hGet hout len
       'r'            -> throwIO $ MercurialServerException $ "return value is fewer than 4 bytes"
       'o'            -> return $ MessageO bdata
       'e'            -> return $ MessageE bdata
-      'd'            -> readMessage hout -- skip this message
+      _ | isLower c  -> readMessage hout -- skip this message
       _              -> throwIO $ MercurialServerException $ "Unknown channel " ++ show c
 
 -- | Read a 32-bit big-endian into an Int