Use ferror() after fflush() to check the error status of the stdio

stream we wrote to.
This commit is contained in:
Todd C. Miller
2016-05-14 18:48:20 -06:00
parent 6d63ed8a92
commit 578af5af4d
2 changed files with 12 additions and 4 deletions

View File

@@ -550,6 +550,7 @@ write_info_log(char *pathbuf, size_t len, struct iolog_details *details,
char * const *av;
FILE *fp;
int fd;
bool rval;
debug_decl(write_info_log, SUDOERS_DEBUG_UTIL)
pathbuf[len] = '\0';
@@ -571,7 +572,11 @@ write_info_log(char *pathbuf, size_t len, struct iolog_details *details,
fputs(*av, fp);
}
fputc('\n', fp);
debug_return_bool(fclose(fp) == 0);
fflush(fp);
rval = !ferror(fp);
fclose(fp);
debug_return_bool(rval);
}
static int

View File

@@ -999,7 +999,7 @@ bool
export_sudoers(const char *sudoers_path, const char *export_path,
bool quiet, bool strict)
{
bool ok = false, need_comma = false;
bool rval = false, need_comma = false;
const int indent = 4;
FILE *export_fp = stdout;
debug_decl(export_sudoers, SUDOERS_DEBUG_UTIL)
@@ -1033,7 +1033,7 @@ export_sudoers(const char *sudoers_path, const char *export_path,
parse_error = true;
errorfile = sudoers_path;
}
ok = !parse_error;
rval = !parse_error;
if (parse_error) {
if (!quiet) {
@@ -1062,7 +1062,10 @@ export_sudoers(const char *sudoers_path, const char *export_path,
fputs("\n}\n", export_fp);
done:
(void)fflush(export_fp);
if (ferror(export_fp))
rval = false;
if (export_fp != stdout && export_fp != NULL)
fclose(export_fp);
debug_return_bool(ok);
debug_return_bool(rval);
}