BUG #15226: (Changes in) LIBPQ prevents proper error captures and crash client programs instead

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: lance(dot)zhang(at)gmail(dot)com
Subject: BUG #15226: (Changes in) LIBPQ prevents proper error captures and crash client programs instead
Date: 2018-06-03 12:03:51
Message-ID: 152802743109.26715.6575483050681335303@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 15226
Logged by: Lance Zhang
Email address: lance(dot)zhang(at)gmail(dot)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;
}

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Janes 2018-06-03 12:55:25 Re: BUG #15226: (Changes in) LIBPQ prevents proper error captures and crash client programs instead
Previous Message PG Bug reporting form 2018-06-03 10:13:36 BUG #15225: [XX000] ERROR: invalid DSA memory alloc request size 1073741824 / Where: parallel worker