Skip to content
Snippets Groups Projects
Commit 1fbdb6bc authored by Michael Meskes's avatar Michael Meskes
Browse files

Fixed segfault in connect when specifying no database name.

parent c3d583dd
No related branches found
No related tags found
No related merge requests found
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.23 2004/08/29 05:06:59 momjian Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.24 2004/12/30 09:36:37 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
......@@ -242,7 +242,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
struct sqlca_t *sqlca = ECPGget_sqlca();
enum COMPAT_MODE compat = c;
struct connection *this;
char *dbname = strdup(name),
char *dbname = name ? strdup(name) : NULL,
*host = NULL,
*tmp,
*port = NULL,
......@@ -275,6 +275,8 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
if (dbname == NULL && connection_name == NULL)
connection_name = "DEFAULT";
if (dbname != NULL)
{
/* get the detail information out of dbname */
if (strchr(dbname, '@') != NULL)
{
......@@ -390,6 +392,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
}
else
realname = strdup(dbname);
}
else
realname = NULL;
/* add connection to our list */
#ifdef ENABLE_THREAD_SAFETY
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.5 2003/11/29 19:52:08 pgsql Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.6 2004/12/30 09:36:37 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
......@@ -46,8 +46,12 @@ ECPGrealloc(void *ptr, long size, int lineno)
char *
ECPGstrdup(const char *string, int lineno)
{
char *new = strdup(string);
char *new;
if (string == NULL)
return NULL;
new = strdup(string);
if (!new)
{
ECPGraise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment