aboutsummaryrefslogtreecommitdiff
path: root/src/BTLS/Types.hs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-09-28 18:31:33 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-09-28 18:31:33 -0400
commit8ac48890e98a4974980b8ca3d5e90a2e52c1a624 (patch)
tree2acbcd7aafdbe245e67d6cf6e224fa654b1d1f28 /src/BTLS/Types.hs
parent924d0109218f04f4a34bbfe1f5d18b75e1d9a66d (diff)
Make NID-to-string routine safer
Eliminate the possibility of a null pointer dereference by converting short names to `Maybe String`.
Diffstat (limited to 'src/BTLS/Types.hs')
-rw-r--r--src/BTLS/Types.hs8
1 files changed, 2 insertions, 6 deletions
diff --git a/src/BTLS/Types.hs b/src/BTLS/Types.hs
index 7a821f8..03f9083 100644
--- a/src/BTLS/Types.hs
+++ b/src/BTLS/Types.hs
@@ -14,9 +14,7 @@
module BTLS.Types where
-import Foreign (Ptr, nullPtr)
-import Foreign.C (peekCString)
-import Foreign.Marshal.Unsafe (unsafeLocalState)
+import Foreign (Ptr)
import BTLS.BoringSSL.Base (EVPMD)
import BTLS.BoringSSL.Digest (evpMDType)
@@ -29,6 +27,4 @@ instance Eq Algorithm where
Algorithm a == Algorithm b = evpMDType a == evpMDType b
instance Show Algorithm where
- show (Algorithm md) =
- let sn = objNID2SN (evpMDType md) in
- if sn == nullPtr then "<algorithm>" else unsafeLocalState (peekCString sn)
+ show (Algorithm md) = maybe "<algorithm>" id (objNID2SN (evpMDType md))