mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
Fixed segfault in connect when specifying no database name.
This commit is contained in:
parent
c3d583ddce
commit
1fbdb6bc9f
@ -1,4 +1,4 @@
|
|||||||
/* $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
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#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();
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
enum COMPAT_MODE compat = c;
|
enum COMPAT_MODE compat = c;
|
||||||
struct connection *this;
|
struct connection *this;
|
||||||
char *dbname = strdup(name),
|
char *dbname = name ? strdup(name) : NULL,
|
||||||
*host = NULL,
|
*host = NULL,
|
||||||
*tmp,
|
*tmp,
|
||||||
*port = NULL,
|
*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)
|
if (dbname == NULL && connection_name == NULL)
|
||||||
connection_name = "DEFAULT";
|
connection_name = "DEFAULT";
|
||||||
|
|
||||||
|
if (dbname != NULL)
|
||||||
|
{
|
||||||
/* get the detail information out of dbname */
|
/* get the detail information out of dbname */
|
||||||
if (strchr(dbname, '@') != NULL)
|
if (strchr(dbname, '@') != NULL)
|
||||||
{
|
{
|
||||||
@ -390,6 +392,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
realname = strdup(dbname);
|
realname = strdup(dbname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
realname = NULL;
|
||||||
|
|
||||||
/* add connection to our list */
|
/* add connection to our list */
|
||||||
#ifdef ENABLE_THREAD_SAFETY
|
#ifdef ENABLE_THREAD_SAFETY
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $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
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
@ -46,8 +46,12 @@ ECPGrealloc(void *ptr, long size, int lineno)
|
|||||||
char *
|
char *
|
||||||
ECPGstrdup(const char *string, int lineno)
|
ECPGstrdup(const char *string, int lineno)
|
||||||
{
|
{
|
||||||
char *new = strdup(string);
|
char *new;
|
||||||
|
|
||||||
|
if (string == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
new = strdup(string);
|
||||||
if (!new)
|
if (!new)
|
||||||
{
|
{
|
||||||
ECPGraise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
|
ECPGraise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user