Skip to content

Commit 17bcdd0

Browse files
author
Michael Meskes
committed
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.
1 parent 8d65ea2 commit 17bcdd0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
326326

327327
if (dbname != NULL)
328328
{
329-
/* get the detail information out of dbname */
329+
/* get the detail information from dbname */
330330
if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0)
331331
{
332332
int offset = 0;
@@ -345,7 +345,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
345345
/*------
346346
* new style:
347347
* <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
348-
* [/db name][?options]
348+
* [/db-name][?options]
349349
*------
350350
*/
351351
offset += strlen("postgresql://");
@@ -420,8 +420,10 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
420420
}
421421
}
422422
else
423-
host = ecpg_strdup(dbname + offset, lineno);
424-
423+
{
424+
if (*(dbname + offset) != '\0')
425+
host = ecpg_strdup(dbname + offset, lineno);
426+
}
425427
}
426428
}
427429
else

0 commit comments

Comments
 (0)