Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3704b99

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 parentdf1a06e commit3704b99

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 19 additions & 15 deletions
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-
charerrorMessage[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-
returnconn;
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+
charerrorMessage[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+
returnconn;
132+
}
133+
}
131134
conn->status=connectDB(conn);
132135
returnconn;
133136
}
@@ -164,8 +167,9 @@ connectDB(PGconn *conn)
164167
user=fe_getauthname(conn->errorMessage);
165168
if (!user)
166169
gotoconnect_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)

[8]ページ先頭

©2009-2025 Movatter.jp