Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2114910

Browse files
committed
Ensure ParseTzFile() closes the input file after failing.
We hadn't noticed this because (a) few people feed invalid timezone abbreviation files to the server, and (b) in typical scenarios guc.c would throw ereport(ERROR) and then transaction abort handling would silently clean up the leaked file reference. However, it was possible to observe file leakage warnings if one breaks an already-active abbreviation file, because guc.c does not throw ERROR when loading supposedly-validated settings during session start or SIGHUP processing. Report and fix by Kyotaro Horiguchi (cosmetic adjustments by me) Discussion: https://postgr.es/m/[email protected]
1 parent 9f3af6d commit 2114910

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/backend/utils/misc/tzparser.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ ParseTzFile(const char *filename, int depth,
365365
{
366366
GUC_check_errmsg("could not read time zone file \"%s\": %m",
367367
filename);
368-
return -1;
368+
n = -1;
369+
break;
369370
}
370371
/* else we're at EOF after all */
371372
break;
@@ -375,7 +376,8 @@ ParseTzFile(const char *filename, int depth,
375376
/* the line is too long for tzbuf */
376377
GUC_check_errmsg("line is too long in time zone file \"%s\", line %d",
377378
filename, lineno);
378-
return -1;
379+
n = -1;
380+
break;
379381
}
380382

381383
/* skip over whitespace */
@@ -398,12 +400,13 @@ ParseTzFile(const char *filename, int depth,
398400
{
399401
GUC_check_errmsg("@INCLUDE without file name in time zone file \"%s\", line %d",
400402
filename, lineno);
401-
return -1;
403+
n = -1;
404+
break;
402405
}
403406
n = ParseTzFile(includeFile, depth + 1,
404407
base, arraysize, n);
405408
if (n < 0)
406-
return -1;
409+
break;
407410
continue;
408411
}
409412

@@ -414,12 +417,18 @@ ParseTzFile(const char *filename, int depth,
414417
}
415418

416419
if (!splitTzLine(filename, lineno, line, &tzentry))
417-
return -1;
420+
{
421+
n = -1;
422+
break;
423+
}
418424
if (!validateTzEntry(&tzentry))
419-
return -1;
425+
{
426+
n = -1;
427+
break;
428+
}
420429
n = addToArray(base, arraysize, n, &tzentry, override);
421430
if (n < 0)
422-
return -1;
431+
break;
423432
}
424433

425434
FreeFile(tzFile);

0 commit comments

Comments
 (0)