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

Commit63edc5c

Browse files
committed
Fix security problem with psql \e where temp file could be an existing
symlink created by someone else, and therefore modifyable by someone else.
1 parent3f19987 commit63edc5c

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

‎src/bin/psql/command.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.38 2000/11/13 23:37:53 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.39 2000/11/25 06:21:54 momjian Exp $
77
*/
88
#include"postgres.h"
99
#include"command.h"
@@ -13,7 +13,8 @@
1313
#include<ctype.h>
1414
#ifndefWIN32
1515
#include<sys/types.h>/* for umask() */
16-
#include<sys/stat.h>/* for umask(), stat() */
16+
#include<sys/stat.h>/* for stat() */
17+
#include<fcntl.h>/* open() flags */
1718
#include<unistd.h>/* for geteuid(), getpid(), stat() */
1819
#else
1920
#include<win32.h>
@@ -1397,7 +1398,8 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
13971398
FILE*stream;
13981399
constchar*fname;
13991400
boolerror= false;
1400-
1401+
intfd;
1402+
14011403
#ifndefWIN32
14021404
structstatbefore,
14031405
after;
@@ -1411,7 +1413,6 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
14111413
{
14121414
/* make a temp file to edit */
14131415
#ifndefWIN32
1414-
mode_toldumask;
14151416
constchar*tmpdirenv=getenv("TMPDIR");
14161417

14171418
sprintf(fnametmp,"%s/psql.edit.%ld.%ld",
@@ -1422,15 +1423,11 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
14221423
#endif
14231424
fname= (constchar*)fnametmp;
14241425

1425-
#ifndefWIN32
1426-
oldumask=umask(0177);
1427-
#endif
1428-
stream=fopen(fname,"w");
1429-
#ifndefWIN32
1430-
umask(oldumask);
1431-
#endif
1426+
fd=open(fname,O_WRONLY|O_CREAT|O_EXCL,0600);
1427+
if (fd!=-1)
1428+
stream=fdopen(fd,"w");
14321429

1433-
if (!stream)
1430+
if (fd==-1||!stream)
14341431
{
14351432
psql_error("couldn't open temp file %s: %s\n",fname,strerror(errno));
14361433
error= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp