aboutsummaryrefslogtreecommitdiff
path: root/src/BTLS/BoringSSL/Obj.chs
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/BoringSSL/Obj.chs
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/BoringSSL/Obj.chs')
-rw-r--r--src/BTLS/BoringSSL/Obj.chs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/BTLS/BoringSSL/Obj.chs b/src/BTLS/BoringSSL/Obj.chs
index a337ad5..7e132e7 100644
--- a/src/BTLS/BoringSSL/Obj.chs
+++ b/src/BTLS/BoringSSL/Obj.chs
@@ -16,8 +16,15 @@ module BTLS.BoringSSL.Obj
( objNID2SN
) where
-import Foreign.C (CString)
+import Foreign (nullPtr)
+import Foreign.C (CString, peekCString)
#include <openssl/obj.h>
-{#fun pure OBJ_nid2sn as objNID2SN {`Int'} -> `CString'#}
+{#fun pure OBJ_nid2sn as objNID2SN
+ {`Int'} -> `Maybe String' peekCStringOrNull*#}
+
+peekCStringOrNull :: CString -> IO (Maybe String)
+peekCStringOrNull ptr
+ | ptr == nullPtr = return Nothing
+ | otherwise = Just <$> peekCString ptr