Go over all OpenSSL return values and make sure we compare them
authorMagnus Hagander <magnus@hagander.net>
Wed, 28 Jan 2009 15:06:48 +0000 (15:06 +0000)
committerMagnus Hagander <magnus@hagander.net>
Wed, 28 Jan 2009 15:06:48 +0000 (15:06 +0000)
to the documented API value. The previous code got it right as
it's implemented, but accepted too much/too little compared to
the API documentation.

Per comment from Zdenek Kotala.

src/backend/libpq/be-secure.c
src/interfaces/libpq/fe-secure.c

index 2ef6b4ac0b4b4fc650e701d3e3500beb13ae91f8..b854d4337c7d191b0f7f1b6296eac064898f16dc 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.43.2.4 2007/05/18 01:20:48 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.43.2.5 2009/01/28 15:06:48 mha Exp $
  *
  *   Since the server static private key ($DataDir/server.key)
  *   will normally be stored unencrypted so that the database
@@ -700,7 +700,7 @@ initialize_SSL(void)
         * Load and verify certificate and private key
         */
        snprintf(fnbuf, sizeof(fnbuf), "%s/server.crt", DataDir);
-       if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
+       if (SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM) != 1)
            ereport(FATAL,
                    (errcode(ERRCODE_CONFIG_FILE_ERROR),
              errmsg("could not load server certificate file \"%s\": %s",
@@ -720,12 +720,12 @@ initialize_SSL(void)
                         fnbuf),
                     errdetail("File must be owned by the database user and must have no permissions for \"group\" or \"other\".")));
 
-       if (!SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
+       if (SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM) != 1)
            ereport(FATAL,
                    (errmsg("could not load private key file \"%s\": %s",
                            fnbuf, SSLerrmessage())));
 
-       if (!SSL_CTX_check_private_key(SSL_context))
+       if (SSL_CTX_check_private_key(SSL_context) != 1)
            ereport(FATAL,
                    (errmsg("check of private key failed: %s",
                            SSLerrmessage())));
@@ -741,7 +741,7 @@ initialize_SSL(void)
 
    /* accept client certificates, but don't require them. */
    snprintf(fnbuf, sizeof(fnbuf), "%s/root.crt", DataDir);
-   if (!SSL_CTX_load_verify_locations(SSL_context, fnbuf, CA_PATH))
+   if (SSL_CTX_load_verify_locations(SSL_context, fnbuf, CA_PATH) != 1)
    {
        /* Not fatal - we do not require client certificates */
        ereport(LOG,
index dedf808d027c28cffa6782261db799c4f6b2b825..3a445b780d030aa1ba80e501800bc2987d65ca50 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.32.2.1 2003/12/18 22:49:34 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.32.2.2 2009/01/28 15:06:48 mha Exp $
  *
  * NOTES
  *   The client *requires* a valid server certificate.  Since
@@ -788,7 +788,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
    fclose(fp);
 
    /* verify that the cert and key go together */
-   if (!X509_check_private_key(*x509, *pkey))
+   if (X509_check_private_key(*x509, *pkey) != 1)
    {
        printfPQExpBuffer(&conn->errorMessage,
            libpq_gettext("certificate/private key mismatch (%s): %s\n"),
@@ -848,7 +848,7 @@ initialize_SSL(PGconn *conn)
            return -1;
 #endif
        }
-       if (!SSL_CTX_load_verify_locations(SSL_context, fnbuf, 0))
+       if (SSL_CTX_load_verify_locations(SSL_context, fnbuf, 0) != 1)
        {
            printfPQExpBuffer(&conn->errorMessage,
                              libpq_gettext("could not read root certificate list (%s): %s\n"),