Skip to content

Commit aef926f

Browse files
committed
check for potential errors when fgets() returns NULL
1 parent b95a158 commit aef926f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/dir.c

+12
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ dir_list_file(parray *files, const char *root, bool exclude, bool follow_symlink
514514
parray_append(black_list, pgut_strdup(black_item));
515515
}
516516

517+
if (ferror(black_list_file))
518+
elog(ERROR, "Failed to read from file: \"%s\"", path);
519+
517520
fio_close_stream(black_list_file);
518521
parray_qsort(black_list, BlackListCompare);
519522
}
@@ -1154,6 +1157,9 @@ read_tablespace_map(parray *files, const char *backup_dir)
11541157
parray_append(files, file);
11551158
}
11561159

1160+
if (ferror(fp))
1161+
elog(ERROR, "Failed to read from file: \"%s\"", map_path);
1162+
11571163
fio_close_stream(fp);
11581164
}
11591165

@@ -1529,6 +1535,9 @@ dir_read_file_list(const char *root, const char *external_prefix,
15291535
parray_append(files, file);
15301536
}
15311537

1538+
if (ferror(fp))
1539+
elog(ERROR, "Failed to read from file: \"%s\"", file_txt);
1540+
15321541
fio_close_stream(fp);
15331542
return files;
15341543
}
@@ -1775,6 +1784,9 @@ read_database_map(pgBackup *backup)
17751784
parray_append(database_map, db_entry);
17761785
}
17771786

1787+
if (ferror(fp))
1788+
elog(ERROR, "Failed to read from file: \"%s\"", database_map_path);
1789+
17781790
fio_close_stream(fp);
17791791

17801792
/* Return NULL if file is empty */

src/restore.c

+3
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,9 @@ read_timeline_history(TimeLineID targetTLI)
996996
/* we ignore the remainder of each line */
997997
}
998998

999+
if (fd && (ferror(fd)))
1000+
elog(ERROR, "Failed to read from file: \"%s\"", path);
1001+
9991002
if (fd)
10001003
fclose(fd);
10011004

src/utils/configuration.c

+3
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ config_read_opt(const char *path, ConfigOption options[], int elevel,
523523
}
524524
}
525525

526+
if (ferror(fp))
527+
elog(ERROR, "Failed to read from file: \"%s\"", path);
528+
526529
fio_close_stream(fp);
527530

528531
return parsed_options;

0 commit comments

Comments
 (0)