From aaa2e8ddecf85903d71146532e40a14ea952ca2e Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 2 Feb 2021 15:06:38 -0700 Subject: [PATCH] Don't close fp in sudoers_parse_ldif() The caller should be the one to handle this. --- plugins/sudoers/cvtsudoers.c | 13 +++++++++---- plugins/sudoers/parse_ldif.c | 3 --- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/sudoers/cvtsudoers.c b/plugins/sudoers/cvtsudoers.c index 5d1ccdd0c..cebe5652e 100644 --- a/plugins/sudoers/cvtsudoers.c +++ b/plugins/sudoers/cvtsudoers.c @@ -609,16 +609,21 @@ parse_ldif(struct sudoers_parse_tree *parse_tree, const char *input_file, struct cvtsudoers_config *conf) { FILE *fp = stdin; + bool ret = false; debug_decl(parse_ldif, SUDOERS_DEBUG_UTIL); /* Open LDIF file and parse it. */ if (strcmp(input_file, "-") != 0) { if ((fp = fopen(input_file, "r")) == NULL) - sudo_fatal(U_("unable to open %s"), input_file); + sudo_warn(U_("unable to open %s"), input_file); } - - debug_return_bool(sudoers_parse_ldif(parse_tree, fp, conf->sudoers_base, - conf->store_options)); + if (fp != NULL) { + ret = sudoers_parse_ldif(parse_tree, fp, conf->sudoers_base, + conf->store_options); + if (fp != stdin) + fclose(fp); + } + debug_return_bool(ret); } static bool diff --git a/plugins/sudoers/parse_ldif.c b/plugins/sudoers/parse_ldif.c index 059478f31..40d10cdfc 100644 --- a/plugins/sudoers/parse_ldif.c +++ b/plugins/sudoers/parse_ldif.c @@ -775,8 +775,5 @@ sudoers_parse_ldif(struct sudoers_parse_tree *parse_tree, rbdestroy(groupcache, str_list_free); rbdestroy(hostcache, str_list_free); - if (fp != stdin) - fclose(fp); - debug_return_bool(errors == 0); }