Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix memory aliasing bug related to `errorMessage`

Hat tip to Joey Adams for spotting the bug.
  • Loading branch information...
commit 284bacdbe377470051a29a69dc14729bef781b81 1 parent 49a6b37
@lpsmith authored
Showing with 7 additions and 16 deletions.
  1. +5 −14 Database/PostgreSQL/LibPQ.hsc
  2. +2 −2 postgresql-libpq.cabal
View
19 Database/PostgreSQL/LibPQ.hsc
@@ -585,8 +585,11 @@ serverVersion connection =
-- same across operations on the 'Connection'.
errorMessage :: Connection
-> IO (Maybe B.ByteString)
-errorMessage = flip maybeBsFromConn c_PQerrorMessage
-
+errorMessage conn = withConn conn $ \cptr -> do
+ strptr <- c_PQerrorMessage cptr
+ if strptr == nullPtr
+ then return Nothing
+ else Just `fmap` B.packCString strptr
-- | Obtains the file descriptor number of the connection socket to
-- the server. (This will not change during normal operation, but
@@ -1954,18 +1957,6 @@ enumFromResult result f = fmap (toEnum . fromIntegral) $ withResult result f
-- | Returns a ByteString with a finalizer that touches the ForeignPtr
--- PGconn that \"owns\" the CString to keep it alive.
---
--- The CString must be a null terminated c string. nullPtrs are
--- treated as 'Nothing'.
-maybeBsFromConn :: Connection
- -> (Ptr PGconn -> IO CString)
- -> IO (Maybe B.ByteString)
-maybeBsFromConn connection f =
- withConn' connection $ \fp -> maybeBsFromForeignPtr fp f
-
-
--- | Returns a ByteString with a finalizer that touches the ForeignPtr
-- PGresult that \"owns\" the CString to keep it alive.
--
-- The CString must be a null terminated c string. nullPtrs are
View
4 postgresql-libpq.cabal
@@ -1,5 +1,5 @@
Name: postgresql-libpq
-Version: 0.7
+Version: 0.7.1
Synopsis: low-level binding to libpq
Description: This is a binding to libpq: the C application
@@ -38,4 +38,4 @@ source-repository head
source-repository this
type: git
location: http://github.com/lpsmith/postgresql-libpq
- tag: v0.7
+ tag: v0.7.1
Please sign in to comment.
Something went wrong with that request. Please try again.