2

I have a connection from a postgres client (Windows 7) to a remote Postgres server (Ubuntu) - Postgres version 9.5.

The postgres client is a c-program using embedded sql (libecpg.dll).

When I pull the network cable after the connection is established, I get:

Unhandled exception at 0x1000bca0 in ...exe: 0xC0000005: Access violation reading location 0x00000000

In the debugger call stack, the last 4 entries are for

libecpg.dll:   libecpg.dll!100047f7(), 
libecpg.dll!100041fd(), 
libecpg.dll!10008bc8(), 
libecpg.dll!10008431(),  ....

Did further research:

The access violation occurs in function fmtstr() because the parameter value is NULL

static void
fmtstr(char *value, int leftjust, int minlen, int maxwidth, int pointflag, PrintfTarget *target)
{
int         padlen,
            vallen;         /* amount to pad */
/*
 * If a maxwidth (precision) is specified, we must not fetch more bytes
 * than that.
 */
if (pointflag)
    vallen = pg_strnlen(value, maxwidth);
else
    vallen = strlen(value); // value == NULL
...

The parameter value is filled from a va_arg() call in function dopr():

static void dopr(PrintfTarget *target, const char *format, va_list args)
    ...
    case 's':
        if (!have_star)
        {
            if (pointflag)
                precision = accum;
            else
                fieldwidth = accum;
        }
        if (have_dollar)
            strvalue = argvalues[fmtpos].cptr;
        else
            strvalue = va_arg(args, char *);
        fmtstr(strvalue, leftjust, fieldwidth, precision, pointflag,
                   target);
        break;
        ...

The access violation only occurs if I pull the network cable but not if I deactivate the network.

In function ecpg_execute():

if (stmt->statement_type == ECPGst_execute) {
    ...
}
else
{
    if (stmt->nparams == 0)
    {
        **stmt->results** = PQexec(stmt->connection->connection, stmt->command);
        ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
    }
    else
    {
        stmt->results = PQexecParams(stmt->connection->connection, stmt->command, stmt->nparams, NULL, (const char *const *) stmt->paramvalues, NULL, NULL, 0);

    ...
    }

When pulling the network cable stmt->results is not NULL

When deactivating the network stmt->results is NULL

walter t
  • 21
  • 2
  • 1
    [Configure the symbol path](https://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Windows#Configuring_the_symbol_path) to include the symbols for ecpg and your application. Then cause the crash again and examine the stack trace. – Laurenz Albe Sep 06 '16 at 09:47

0 Answers0