1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Do not use an empty hostname.

When trying to connect to a given database libecpg should not try using an
empty hostname if no hostname was given.
This commit is contained in:
Michael Meskes
2014-01-01 12:24:19 +01:00
parent 9a6e2b150f
commit 8404037d89

View File

@ -325,7 +325,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
if (dbname != NULL) if (dbname != NULL)
{ {
/* get the detail information out of dbname */ /* get the detail information from dbname */
if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0) if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0)
{ {
int offset = 0; int offset = 0;
@ -344,7 +344,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
/*------ /*------
* new style: * new style:
* <tcp|unix>:postgresql://server[:port|:/unixsocket/path:] * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
* [/db name][?options] * [/db-name][?options]
*------ *------
*/ */
offset += strlen("postgresql://"); offset += strlen("postgresql://");
@ -427,8 +427,11 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
} }
else else
{ {
host = ecpg_strdup(dbname + offset, lineno); if (*(dbname + offset) != '\0')
connect_params++; {
host = ecpg_strdup(dbname + offset, lineno);
connect_params++;
}
} }
} }