failed connect from ecpg destroys evidence of failure

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: failed connect from ecpg destroys evidence of failure
Date: 2001-06-12 21:48:02
Message-ID: 200106122148.f5CLm2l82292@hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Rafal Boni (rafal(dot)boni(at)edial(dot)com) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
failed connect from ecpg destroys evidence of failure

Long Description
PostgreSQL version 7.1.2, built from source, on Linux (RH 6.2)

If a CONNECT form ecpg fails, the debugging output, as well as the error returned is garbage, as the parameters passed in are freed right after the call to:

PQsetdbLogin(host, port, options, NULL, realname, user, passwd);
[src/interfaces/ecpg/lib/connect.c, around line 413]

but before the error checking or post-setdbLogin debugging checks
which use them.

Restructuring the code a little bit give both a sane error message and more useful debug output. I've done that in my tree, but attempting to paste it in here is bad mojo (it trashes the rest of my message probably due to tab's), but I'll send it via email to anyone that's interested.

--rafal

Sample Code
foo_open_db(char *hostname, char *username, char *password,
char *db_name)
{
EXEC SQL BEGIN DECLARE SECTION;
char cUserName[256];
char cPassword[256];
char cDbName[256];
EXEC SQL END DECLARE SECTION;

ECPGdebug(1, stdout);

strncpy(cUserName, username, sizeof(cUserName) - 1);
cUserName[sizeof(cUserName) - 1] = '\0';

strncpy(cPassword, password, sizeof(cPassword) - 1);
cPassword[sizeof(cPassword) - 1] = '\0';

snprintf(cDbName, sizeof(cDbName) - 1, "tcp:postgresql://%s/%s", hostname, db_name);
cDbName[sizeof(cDbName) - 1] = '\0';

printf("attempting to connect to %s, user %s, pass %s\n", cDbName,
cUserName,

EXEC SQL CONNECT TO :cDbName
USER :cUserName IDENTIFIED BY :cPassword;

if (sqlca.sqlcode != 0){
fprintf(stderr, "Unable to connect to database:%s\n",
sqlca.sqlerrm.sqlerrmc);
return -1;
}

No file was uploaded with this report

Browse pgsql-bugs by date

  From Date Subject
Next Message Rainer Mager 2001-06-12 22:19:06 RE: Index files grow forever?
Previous Message Tom Lane 2001-06-12 21:39:51 Re: PHP's pg_connect() and non-standard location of the socket (was: REPOST: redefining location of the socket file /tmp/.s.PGSQL.5432)