From 578af5af4d069e9daac94c2556a5004965347dee Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 14 May 2016 18:48:20 -0600 Subject: [PATCH] Use ferror() after fflush() to check the error status of the stdio stream we wrote to. --- plugins/sudoers/iolog.c | 7 ++++++- plugins/sudoers/visudo_json.c | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index a0ba31933..bde966ec3 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -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 diff --git a/plugins/sudoers/visudo_json.c b/plugins/sudoers/visudo_json.c index ca1ecc68d..ad34aa533 100644 --- a/plugins/sudoers/visudo_json.c +++ b/plugins/sudoers/visudo_json.c @@ -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); } -- 2.40.0