提交 742e5415 编写于 作者: D Daniel Gustafsson

Always read returnvalue from stat calls

{f}stat() can fail and reading the stat buffer without checking for
status is bad hygiene. Ensure to always test return value and take
the appropriate error path in case of stat error.
上级 00735953
......@@ -222,7 +222,9 @@ slurp_oid_files(migratorContext *ctx)
if (!oid_dump)
pg_log(ctx, PG_FATAL, "Could not open necessary file: %s\n", GLOBAL_OIDS_DUMP_FILE);
fstat(fileno(oid_dump), &st);
if (fstat(fileno(oid_dump), &st) != 0)
pg_log(ctx, PG_FATAL, "Could not read file \"%s\": %s\n",
GLOBAL_OIDS_DUMP_FILE, strerror(errno));
reserved_oids = pg_malloc(ctx, st.st_size + 1);
fread(reserved_oids, st.st_size, 1, oid_dump);
......@@ -241,7 +243,9 @@ slurp_oid_files(migratorContext *ctx)
if (!oid_dump)
pg_log(ctx, PG_FATAL, "Could not open necessary file: %s\n", filename);
fstat(fileno(oid_dump), &st);
if (fstat(fileno(oid_dump), &st) != 0)
pg_log(ctx, PG_FATAL, "Could not read file \"%s\": %s\n",
filename, strerror(errno));
reserved_oids = pg_malloc(ctx, st.st_size + 1);
fread(reserved_oids, st.st_size, 1, oid_dump);
......
......@@ -2468,8 +2468,7 @@ FileRepMirror_DropFilesFromDir(FileName fileName)
{
if (errno == EPERM)
{
stat(path, &st);
if (S_ISDIR(st.st_mode))
if ((stat(path, &st) >= 0) && (S_ISDIR(st.st_mode)))
continue;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册