From: Todd C. Miller Date: Wed, 8 Jan 2014 23:29:18 +0000 (-0700) Subject: Close export_fp in the error path too, but do not close stdout. X-Git-Tag: SUDO_1_8_10^2~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b5ad37b472ed46baab23f9a76730854aeab71ad;p=sudo Close export_fp in the error path too, but do not close stdout. --- diff --git a/plugins/sudoers/visudo_json.c b/plugins/sudoers/visudo_json.c index 9ebfd51e4..f629435be 100644 --- a/plugins/sudoers/visudo_json.c +++ b/plugins/sudoers/visudo_json.c @@ -984,7 +984,7 @@ export_sudoers(const char *sudoers_path, const char *export_path, { bool ok = false, need_comma = false; const int indent = 4; - FILE *export_fp; + FILE *export_fp = stdout; debug_decl(export_sudoers, SUDO_DEBUG_UTIL) if (strcmp(sudoers_path, "-") == 0) { @@ -996,7 +996,6 @@ export_sudoers(const char *sudoers_path, const char *export_path, goto done; } if (strcmp(export_path, "-") == 0) { - export_fp = stdout; export_path = "stdout"; } else if ((export_fp = fopen(export_path, "w")) == NULL) { if (!quiet) @@ -1037,8 +1036,9 @@ export_sudoers(const char *sudoers_path, const char *export_path, /* Close JSON output. */ fputs("\n}\n", export_fp); - fclose(export_fp); done: + if (export_fp != stdout) + fclose(export_fp); debug_return_bool(ok); }