Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3704b99

Browse files
committed
- libpq calls "fe_getauthname()" two times in "fe-connect.c", but
doesn't free the buffer allocated by this function. - submitted by: Erich Stamberger <eberger@gewi.kfunigraz.ac.at>
1 parent df1a06e commit 3704b99

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/interfaces/libpq/fe-connect.c

+19-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.2 1996/07/12 04:53:57 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.3 1996/07/19 07:00:56 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -114,20 +114,23 @@ PQsetdb(char *pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName)
114114
} else
115115
conn->pgoptions = strdup(pgoptions);
116116

117-
if (!dbName || dbName[0] == '\0') {
118-
char errorMessage[ERROR_MSG_LENGTH];
119-
if (!(tmp = getenv("PGDATABASE")) &&
120-
!(tmp = fe_getauthname(errorMessage))) {
121-
sprintf(conn->errorMessage,
122-
"FATAL: PQsetdb: Unable to determine a database name!\n");
123-
/* pqdebug("%s", conn->errorMessage); */
124-
conn->dbName = NULL;
125-
return conn;
126-
}
117+
if (((tmp = dbName) && (dbName[0] != '\0')) ||
118+
((tmp = getenv("PGDATABASE"))))
127119
conn->dbName = strdup(tmp);
128-
} else
129-
conn->dbName = strdup(dbName);
130-
120+
else {
121+
char errorMessage[ERROR_MSG_LENGTH];
122+
if (tmp = fe_getauthname(errorMessage)) {
123+
conn->dbName = strdup(tmp);
124+
free(tmp);
125+
}
126+
else {
127+
sprintf(conn->errorMessage,
128+
"FATAL: PQsetdb: Unable to determine a database name!\n");
129+
/* pqdebug("%s", conn->errorMessage); */
130+
conn->dbName = NULL;
131+
return conn;
132+
}
133+
}
131134
conn->status = connectDB(conn);
132135
return conn;
133136
}
@@ -164,8 +167,9 @@ connectDB(PGconn *conn)
164167
user = fe_getauthname(conn->errorMessage);
165168
if (!user)
166169
goto connect_errReturn;
167-
strncpy(startup.database,conn->dbName,sizeof(startup.database));
168170
strncpy(startup.user,user,sizeof(startup.user));
171+
free(user);
172+
strncpy(startup.database,conn->dbName,sizeof(startup.database));
169173
strncpy(startup.tty,conn->pgtty,sizeof(startup.tty));
170174
if (conn->pgoptions) {
171175
strncpy(startup.options,conn->pgoptions, sizeof(startup.options));

0 commit comments

Comments
 (0)