7c0489
From: Florian Weimer <fweimer@redhat.com>
7c0489
Date: Tue, 21 Jan 2020 16:11:01 +0000 (+0100)
7c0489
Subject: resolv: Fix file handle leak in __resolv_conf_load [BZ #25429]
7c0489
X-Git-Url: https://sourceware.org/git/?p=glibc.git;a=commitdiff_plain;h=a1a20f029299dc27170912bb9233070c8403444d
7c0489
7c0489
resolv: Fix file handle leak in __resolv_conf_load [BZ #25429]
7c0489
7c0489
res_vinit_1 did not close the stream on errors, only on success.
7c0489
This change moves closing the stream to __resolv_conf_load, for both
7c0489
the success and error cases.
7c0489
7c0489
Fixes commit 89f187a40fc0ad4e22838526bfe34d73f758b776 ("resolv: Use
7c0489
getline for configuration file reading in res_vinit_1") and commit
7c0489
3f853f22c87f0b671c0366eb290919719fa56c0e ("resolv: Lift domain search
7c0489
list limits [BZ #19569] [BZ #21475]"), where memory allocation was
7c0489
introduced into res_vinit_1.
7c0489
7c0489
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
7c0489
---
7c0489
7c0489
diff --git a/resolv/res_init.c b/resolv/res_init.c
7c0489
index 95dce098aa..09345718cd 100644
7c0489
--- a/resolv/res_init.c
7c0489
+++ b/resolv/res_init.c
7c0489
@@ -508,7 +508,6 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser)
7c0489
               continue;
7c0489
             }
7c0489
         }
7c0489
-      fclose (fp);
7c0489
     }
7c0489
   if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0))
7c0489
     {
7c0489
@@ -593,6 +592,13 @@ __resolv_conf_load (struct __res_state *preinit)
7c0489
     }
7c0489
   resolv_conf_parser_free (&parser);
7c0489
 
7c0489
+  if (fp != NULL)
7c0489
+    {
7c0489
+      int saved_errno = errno;
7c0489
+      fclose (fp);
7c0489
+      __set_errno (saved_errno);
7c0489
+    }
7c0489
+
7c0489
   return conf;
7c0489
 }
7c0489