Skip to content

Commit e92877a

Browse files
committed
proper handling of the random bytes buffer and avoids potential memory issues
1 parent fdf8394 commit e92877a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Crypto/Secp256k1.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,9 @@ schnorrSign mGen KeyPair{..} bs
756756
lift $ do
757757
sigBuf <- mallocBytes 64
758758
randomPtr <- case mGen of
759-
Just gen -> fmap castPtr $ BS.useAsCString (BS.pack $ Prelude.take 32 $ randoms gen) return
759+
Just gen -> do
760+
let randomBytes = BS.pack $ Prelude.take 32 $ randoms gen
761+
BS.useAsCStringLen randomBytes $ \(ptr, _) -> pure $ castPtr ptr
760762
Nothing -> pure nullPtr
761763
ret <- Prim.schnorrsigSign ctx sigBuf msgHashPtr keyPairPtr randomPtr
762764
if isSuccess ret

0 commit comments

Comments
 (0)