pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: kamil@mrblur.net
To: pgsql-bugs@postgresql.org
Subject: BUG #7560: Crash on libpq-9.2.0 and openssl-1.0.1c on windows when openssl.cnf is not found
Date: Wed, 19 Sep 2012 16:01:09 +0000
Message-ID: <E1TEMi5-0005WR-6y@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      7560
Logged by:          Kamil KamiƄski
Email address:      kamil@mrblur.net
PostgreSQL version: 9.2.0
Operating system:   Windows
Description:        

When openssl is built on Windows it hardcodes OPENSSLDIR into its sources.
By default it is "/usr/local/openssl", however it defaults to configured
prefix when configuring on windows. In my case it defaulted to a location on
D:\libs\openssl.

This leads to random crashes on PQconnect when using SSL layer as openssl
library tries to open openssl.cnf file (which should be at OPENSSLDIR) and
when it cannot found it - throws an error.
Now, this error is not returned by PQconnect as an connection error, instead
whole app shuts down.

When using psql from windows commandline I got messages complaying about
openssl's BIO layer and missing configuration file.

It is easy to reproduce as openssl allows "OPENSSL_CONF" environment
variable to point at 'proper' configuration.

Just try to do:

$ SET OPENSSL_CONF="invalid_path"
$ psql

(" chars are intented - this way path is invalid and openssl cannot fopen()
it.)


And try with any libPQ-based application - it will crash.


I believe this in fact is a bug as:
 1) OpenSSL(.exe) displays warning about missing file, never throws error
 2) OPENSSL_CONF cannot be overriden from libPQ API
 3) OPENSSL_CONF cannot be overriden from application process as libPQ uses
different environment copies (according to MSDN, verified with
SetEnvironmentVariable call befor delay-load libPQ.dll)
 4) OPENSSL_CONF is used widely and I cannot blindly replace it system-wide
(for instance: OpenVPN installs OpenSSL and configures global variable)
 5) Connection does not return error, instead it crashes whole app.


Some details of my config:
 * Microsof Visual Studio 2010 with all upgrades,
 * Windows 7 x64 as build host
 * OpenSSL 1.0.1c built with defaults (threads, asm), --prefix for nmake
install
 * PostgreSQL 9.2.0 configured with openssl set to my aOpenSSL path
 * My APP is written in C++ (MFC), dynamically linked to libPQ
 * My app crashes directly in PQconnect, server uses SSL
 * sslmode=disable does not crash application,
 * My app connects correctly with sslmode=require if OPENSSL_CONF is set to
a blank file (a valid file to fopen)
 * My app crashes if OPENSSL_MODE is set to anything invalid

Best regards,
Kamil





Message-ID: <E1TEMi5-0005WR-6y@wrigleys.postgresql.org>
Permalink:  ../E1TEMi5-0005WR-6y@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1TEMi5-0005WR-6y@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kamil@mrblur.net
  Subject: Re: BUG #7560: Crash on libpq-9.2.0 and openssl-1.0.1c on windows when openssl.cnf is not found
  In-Reply-To: <E1TEMi5-0005WR-6y@wrigleys.postgresql.org>
  References: <E1TEMi5-0005WR-6y@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox