BUG #15226: (Changes in) LIBPQ prevents proper error captures andcrash client programs instead - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15226: (Changes in) LIBPQ prevents proper error captures andcrash client programs instead
Date
Msg-id 152802743109.26715.6575483050681335303@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #15226: (Changes in) LIBPQ prevents proper error captures andcrash client programs instead  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-bugs
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;
}


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15225: [XX000] ERROR: invalid DSA memory alloc request size1073741824 / Where: parallel worker
Next
From: Jeff Janes
Date:
Subject: Re: BUG #15226: (Changes in) LIBPQ prevents proper error captures andcrash client programs instead