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

Commite882bca

Browse files
committed
libpq: Fix minor TOCTOU violation
libpq checks the permissions of the password file before opening it.The way this is done in two separate operations, a static analyzerwould flag as a time-of-check-time-of-use violation. In practice, youcan't do anything with that, but it still seems better style to fixit.To fix it, open the file first and then check the permissions on theopened file handle.Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>Reviewed-by: Andreas Karlsson <andreas@proxel.se>Discussion:https://www.postgresql.org/message-id/flat/a3356054-14ae-4e7a-acc6-249d19dac20b%40eisentraut.org
1 parente3ec9dc commite882bca

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7452,7 +7452,9 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
74527452
constchar*username,constchar*pgpassfile)
74537453
{
74547454
FILE*fp;
7455+
#ifndefWIN32
74557456
structstatstat_buf;
7457+
#endif
74567458
PQExpBufferDatabuf;
74577459

74587460
if (dbname==NULL||dbname[0]=='\0')
@@ -7477,10 +7479,14 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
74777479
port=DEF_PGPORT_STR;
74787480

74797481
/* If password file cannot be opened, ignore it. */
7480-
if (stat(pgpassfile,&stat_buf)!=0)
7482+
fp=fopen(pgpassfile,"r");
7483+
if (fp==NULL)
74817484
returnNULL;
74827485

74837486
#ifndefWIN32
7487+
if (fstat(fileno(fp),&stat_buf)!=0)
7488+
returnNULL;
7489+
74847490
if (!S_ISREG(stat_buf.st_mode))
74857491
{
74867492
fprintf(stderr,
@@ -7505,10 +7511,6 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
75057511
*/
75067512
#endif
75077513

7508-
fp=fopen(pgpassfile,"r");
7509-
if (fp==NULL)
7510-
returnNULL;
7511-
75127514
/* Use an expansible buffer to accommodate any reasonable line length */
75137515
initPQExpBuffer(&buf);
75147516

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp