From e0e149cebf6660de19f9b64ec1579350c0664a07 Mon Sep 17 00:00:00 2001
From: Shenhao Wang <wangsh.fnst@cn.fujitsu.com>
Date: Thu, 4 Feb 2021 14:35:51 +0800
Subject: [PATCH] fix strchr & strrchr mistake

---
 src/interfaces/ecpg/ecpglib/connect.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 6b0a3067e6..e679169019 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -374,7 +374,8 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 				}
 
 				tmp = last_dir_separator(dbname + offset);
-				if (tmp != NULL)	/* database name given */
+				if (tmp != NULL
+					&& strchr(tmp + 1, ':') == NULL)   /* database name given */
 				{
 					if (tmp[1] != '\0') /* non-empty database name */
 					{
@@ -384,13 +385,13 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 					*tmp = '\0';
 				}
 
-				tmp = strrchr(dbname + offset, ':');
+				tmp = strchr(dbname + offset, ':');
 				if (tmp != NULL)	/* port number or Unix socket path given */
 				{
 					char	   *tmp2;
 
 					*tmp = '\0';
-					if ((tmp2 = strchr(tmp + 1, ':')) != NULL)
+					if ((tmp2 = strrchr(tmp + 1, ':')) != NULL)
 					{
 						*tmp2 = '\0';
 						host = ecpg_strdup(tmp + 1, lineno);
-- 
2.26.2

