sanitize control characters in main thread fatal exceptions
Sponsored-by: Noam Kremen on Patreon
This commit is contained in:
parent
11790df3e6
commit
fdac66ae10
3 changed files with 22 additions and 1 deletions
12
Messages.hs
12
Messages.hs
|
@ -48,12 +48,14 @@ module Messages (
|
||||||
MessageState,
|
MessageState,
|
||||||
prompt,
|
prompt,
|
||||||
mkPrompter,
|
mkPrompter,
|
||||||
|
sanitizeTopLevelExceptionMessages,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import qualified Data.ByteString as S
|
import qualified Data.ByteString as S
|
||||||
import qualified Data.ByteString.Char8 as S8
|
import qualified Data.ByteString.Char8 as S8
|
||||||
|
import System.Exit
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
import Types
|
import Types
|
||||||
|
@ -323,3 +325,13 @@ mkPrompter = getConcurrency >>= \case
|
||||||
(takeMVar l)
|
(takeMVar l)
|
||||||
(\v -> putMVar l v >> cleanup)
|
(\v -> putMVar l v >> cleanup)
|
||||||
(const $ run a)
|
(const $ run a)
|
||||||
|
|
||||||
|
{- Catch all (non-async) exceptions and display, santizing any control
|
||||||
|
- characters in the exceptions. Exits nonzero on exception, so should only
|
||||||
|
- be used at topmost level. -}
|
||||||
|
sanitizeTopLevelExceptionMessages :: IO a -> IO a
|
||||||
|
sanitizeTopLevelExceptionMessages a = catchNonAsync a go
|
||||||
|
where
|
||||||
|
go e = do
|
||||||
|
warningIO (show e)
|
||||||
|
exitWith $ ExitFailure 1
|
||||||
|
|
|
@ -60,3 +60,11 @@ Also: Any place that an exception is thrown with an attacker-controlled value.
|
||||||
other exceptions, including ones thrown by libraries. Catch all exceptions
|
other exceptions, including ones thrown by libraries. Catch all exceptions
|
||||||
at top-level (of program and/or worker threads) and filter out control
|
at top-level (of program and/or worker threads) and filter out control
|
||||||
characters?
|
characters?
|
||||||
|
|
||||||
|
> Fixed with a top-level exception catcher; assuming all worker threads
|
||||||
|
> have something waiting on them that displays or propagates their
|
||||||
|
> exceptions.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
> all [[fixed|done]]! --[[Joey]]
|
||||||
|
|
|
@ -16,6 +16,7 @@ import qualified CmdLine.GitAnnexShell
|
||||||
import qualified CmdLine.GitRemoteTorAnnex
|
import qualified CmdLine.GitRemoteTorAnnex
|
||||||
import qualified Test
|
import qualified Test
|
||||||
import qualified Benchmark
|
import qualified Benchmark
|
||||||
|
import Messages
|
||||||
import Utility.FileSystemEncoding
|
import Utility.FileSystemEncoding
|
||||||
|
|
||||||
#ifdef mingw32_HOST_OS
|
#ifdef mingw32_HOST_OS
|
||||||
|
@ -24,7 +25,7 @@ import Utility.Env.Set
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = withSocketsDo $ do
|
main = sanitizeTopLevelExceptionMessages $ withSocketsDo $ do
|
||||||
useFileSystemEncoding
|
useFileSystemEncoding
|
||||||
ps <- getArgs
|
ps <- getArgs
|
||||||
#ifdef mingw32_HOST_OS
|
#ifdef mingw32_HOST_OS
|
||||||
|
|
Loading…
Reference in a new issue