pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: lance.zhang@gmail.com
Subject: BUG #15226: (Changes in) LIBPQ prevents proper error captures and crash client programs instead
Date: Sun, 03 Jun 2018 12:03:51 +0000
Message-ID: <152802743109.26715.6575483050681335303@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15226
Logged by:          Lance Zhang
Email address:      lance.zhang@gmail.com
PostgreSQL version: 10.4
Operating system:   Windows 10
Description:        

This mimimal test program will not run properly if the SQL supplied is
illegal. It crashes inside libqp. No chance is offered to client program to
detect and correct the error with facilities like PQerrorMessage(...).

#include <stdio.h>
#include <libpq-fe.h>
#include <libpq/libpq-fs.h>

int main()
{
	PGresult * r;
	PGconn * conn;
	ExecStatusType status;
	
        /* Note: if it's a wrong password, the error can be detected and
processed decently. Not when you supply an 
         * non-exisiting dbname, etc. But this is not the point of this bug
report
         */
	conn=PQconnectdb("host=localhost dbname=postgres user=postgres
password='/*YOUR PASSWORD*/'");
	
	if( PQstatus(conn)!=  CONNECTION_OK ){
		fprintf(stderr, "Error connecting to database:%s!\n",
PQerrorMessage(conn));
		PQfinish(conn);
		exit(-1);
	}

        /* The next statement will crash the program inside libpq, because
of the illegal SQL statement */
	r=PQexec(conn,"SELECT SELECT FROM FROM");

        /* the error detection mechanism in the next statement never gets a
chance to be used */
	status=PQresultStatus(r);
	if(status==PGRES_BAD_RESPONSE || status==PGRES_FATAL_ERROR)
	{
		fprintf(stderr,"Error executing SQL:%s!\n", PQerrorMessage(conn));
		PQclear(r);
		PQfinish(conn);
		exit(-2);
	}
	

	PQclear(r);
	PQfinish(conn);
	
	return 0;
}



view thread (2+ messages)  latest in thread

Message-ID: <152802743109.26715.6575483050681335303@wrigleys.postgresql.org>
Permalink:  ../152802743109.26715.6575483050681335303@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152802743109.26715.6575483050681335303@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: noreply@postgresql.org, lance.zhang@gmail.com
  Subject: Re: BUG #15226: (Changes in) LIBPQ prevents proper error captures and crash client programs instead
  In-Reply-To: <152802743109.26715.6575483050681335303@wrigleys.postgresql.org>
  References: <152802743109.26715.6575483050681335303@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