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

Commit570a58f

Browse files
committed
Don't leak a file descriptor when updating pg_pwd file. Also, check for
failure of rename() call.
1 parent8bd6c1f commit570a58f

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

‎src/backend/commands/user.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: user.c,v 1.52 2000/04/12 17:14:59 momjian Exp $
9+
* $Id: user.c,v 1.53 2000/05/04 20:06:07 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -56,6 +56,7 @@ write_password_file(Relation rel)
5656
*tempname;
5757
intbufsize;
5858
FILE*fp;
59+
intflagfd;
5960
mode_toumask;
6061
HeapScanDescscan;
6162
HeapTupletuple;
@@ -75,7 +76,7 @@ write_password_file(Relation rel)
7576
fp=AllocateFile(tempname,"w");
7677
umask(oumask);
7778
if (fp==NULL)
78-
elog(ERROR,"%s: %s",tempname,strerror(errno));
79+
elog(ERROR,"%s: %m",tempname);
7980

8081
/* read table */
8182
scan=heap_beginscan(rel, false,SnapshotSelf,0,NULL);
@@ -129,29 +130,38 @@ write_password_file(Relation rel)
129130
null_v ?"\\N" :nabstimeout((AbsoluteTime)datum_v)/* this is how the
130131
* parser wants it */
131132
);
132-
if (ferror(fp))
133-
elog(ERROR,"%s: %s",tempname,strerror(errno));
134-
fflush(fp);
135133
}
136134
heap_endscan(scan);
135+
136+
fflush(fp);
137+
if (ferror(fp))
138+
elog(ERROR,"%s: %m",tempname);
137139
FreeFile(fp);
138140

139141
/*
140142
* And rename the temp file to its final name, deleting the old
141143
* pg_pwd.
142144
*/
143-
rename(tempname,filename);
145+
if (rename(tempname,filename))
146+
elog(ERROR,"rename %s to %s: %m",tempname,filename);
147+
148+
pfree((void*)tempname);
149+
pfree((void*)filename);
144150

145151
/*
146152
* Create a flag file the postmaster will detect the next time it
147153
* tries to authenticate a user. The postmaster will know to reload
148-
* the pg_pwd file contents.
154+
* the pg_pwd file contents. Note: we used to elog(ERROR) if the
155+
* creat() call failed, but it's a little silly to abort the transaction
156+
* at this point, so let's just make it a NOTICE.
149157
*/
150158
filename=crypt_getpwdreloadfilename();
151-
if (creat(filename,S_IRUSR |S_IWUSR)==-1)
152-
elog(ERROR,"%s: %s",filename,strerror(errno));
153-
154-
pfree((void*)tempname);
159+
flagfd=creat(filename,S_IRUSR |S_IWUSR);
160+
if (flagfd==-1)
161+
elog(NOTICE,"%s: %m",filename);
162+
else
163+
close(flagfd);
164+
pfree((void*)filename);
155165
}
156166

157167

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp