From aef926ffd0aaeadd169c0c98bcf08040fbf97f9f Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Tue, 27 Aug 2019 19:24:10 +0300 Subject: [PATCH] check for potential errors when fgets() returns NULL --- src/dir.c | 12 ++++++++++++ src/restore.c | 3 +++ src/utils/configuration.c | 3 +++ 3 files changed, 18 insertions(+) diff --git a/src/dir.c b/src/dir.c index c122d3a3..2f6d8090 100644 --- a/src/dir.c +++ b/src/dir.c @@ -514,6 +514,9 @@ dir_list_file(parray *files, const char *root, bool exclude, bool follow_symlink parray_append(black_list, pgut_strdup(black_item)); } + if (ferror(black_list_file)) + elog(ERROR, "Failed to read from file: \"%s\"", path); + fio_close_stream(black_list_file); parray_qsort(black_list, BlackListCompare); } @@ -1154,6 +1157,9 @@ read_tablespace_map(parray *files, const char *backup_dir) parray_append(files, file); } + if (ferror(fp)) + elog(ERROR, "Failed to read from file: \"%s\"", map_path); + fio_close_stream(fp); } @@ -1529,6 +1535,9 @@ dir_read_file_list(const char *root, const char *external_prefix, parray_append(files, file); } + if (ferror(fp)) + elog(ERROR, "Failed to read from file: \"%s\"", file_txt); + fio_close_stream(fp); return files; } @@ -1775,6 +1784,9 @@ read_database_map(pgBackup *backup) parray_append(database_map, db_entry); } + if (ferror(fp)) + elog(ERROR, "Failed to read from file: \"%s\"", database_map_path); + fio_close_stream(fp); /* Return NULL if file is empty */ diff --git a/src/restore.c b/src/restore.c index ed401d14..73a25929 100644 --- a/src/restore.c +++ b/src/restore.c @@ -996,6 +996,9 @@ read_timeline_history(TimeLineID targetTLI) /* we ignore the remainder of each line */ } + if (fd && (ferror(fd))) + elog(ERROR, "Failed to read from file: \"%s\"", path); + if (fd) fclose(fd); diff --git a/src/utils/configuration.c b/src/utils/configuration.c index cf5436f2..74fc7389 100644 --- a/src/utils/configuration.c +++ b/src/utils/configuration.c @@ -523,6 +523,9 @@ config_read_opt(const char *path, ConfigOption options[], int elevel, } } + if (ferror(fp)) + elog(ERROR, "Failed to read from file: \"%s\"", path); + fio_close_stream(fp); return parsed_options;