]> granicus.if.org Git - postgresql/commitdiff
Do not use an empty hostname.
authorMichael Meskes <meskes@postgresql.org>
Wed, 1 Jan 2014 11:24:19 +0000 (12:24 +0100)
committerMichael Meskes <meskes@postgresql.org>
Wed, 1 Jan 2014 11:40:42 +0000 (12:40 +0100)
When trying to connect to a given database libecpg should not try using an
empty hostname if no hostname was given.

src/interfaces/ecpg/ecpglib/connect.c

index 49f2d546bbe1bb5f1dbbca66b77b0c399f51d6cd..55c56807b2f6b628a4f976a284038a25d95ea59e 100644 (file)
@@ -325,7 +325,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 
        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)
                {
                        int                     offset = 0;
@@ -344,7 +344,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
                                /*------
                                 * new style:
                                 *      <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
-                                *      [/db name][?options]
+                                *      [/db-name][?options]
                                 *------
                                 */
                                offset += strlen("postgresql://");
@@ -427,8 +427,11 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
                                }
                                else
                                {
-                                       host = ecpg_strdup(dbname + offset, lineno);
-                                       connect_params++;
+                                       if (*(dbname + offset) != '\0')
+                                       {
+                                               host = ecpg_strdup(dbname + offset, lineno);
+                                               connect_params++;
+                                       }
                                }
 
                        }