Skip to content

Commit e933978

Browse files
committed
In passwordFromFile, don't leak the open file after stat failures.
Oversight in e882bca. Per Coverity.
1 parent c1ff2d8 commit e933978

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7482,13 +7482,17 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
74827482

74837483
#ifndef WIN32
74847484
if (fstat(fileno(fp), &stat_buf) != 0)
7485+
{
7486+
fclose(fp);
74857487
return NULL;
7488+
}
74867489

74877490
if (!S_ISREG(stat_buf.st_mode))
74887491
{
74897492
fprintf(stderr,
74907493
libpq_gettext("WARNING: password file \"%s\" is not a plain file\n"),
74917494
pgpassfile);
7495+
fclose(fp);
74927496
return NULL;
74937497
}
74947498

@@ -7498,6 +7502,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
74987502
fprintf(stderr,
74997503
libpq_gettext("WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
75007504
pgpassfile);
7505+
fclose(fp);
75017506
return NULL;
75027507
}
75037508
#else

0 commit comments

Comments
 (0)