Message ID | 4d8628bf1d8630c16de30d47732058ec82293429.1579631655.git.fweimer@redhat.com |
---|---|
State | Committed |
Headers |
Received: (qmail 93626 invoked by alias); 21 Jan 2020 18:42:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 93540 invoked by uid 89); 21 Jan 2020 18:42:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=21475, Lift, lift X-HELO: us-smtp-delivery-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579632121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2hSV7vcZa+U8O4Nnu6qEWkeZbphT/cpRwm/UNy63jE=; b=GJVtwvXVvy8VaMs1G46BQWLBlCyieEY7ziaeg5LghH7qaH2SxqN8bVNFdOM+NW1d5Q0OYo 6cT4hT35WBT3xaSMUvvcVC9doTHymq74EV6OPPqu2smqOmdJG1rJPlbr327MCjAhDRKThj 7Bqjp5ItZQPkU69woKfI39sCkQ84OKs= From: Florian Weimer <fweimer@redhat.com> To: libc-alpha@sourceware.org Subject: [PATCH 3/5] resolv: Fix file handle leak in __resolv_conf_load [BZ #25429] In-Reply-To: <cover.1579631655.git.fweimer@redhat.com> References: <cover.1579631655.git.fweimer@redhat.com> Message-Id: <4d8628bf1d8630c16de30d47732058ec82293429.1579631655.git.fweimer@redhat.com> Date: Tue, 21 Jan 2020 19:41:55 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: quoted-printable |
Commit Message
Florian Weimer
Jan. 21, 2020, 6:41 p.m. UTC
res_vinit_1 did not close the stream on errors, only on success. This change moves closing the stream to __resolv_conf_load, for both the success and error cases. Fixes commit 89f187a40fc0ad4e22838526bfe34d73f758b776 ("resolv: Use getline for configuration file reading in res_vinit_1") and commit 3f853f22c87f0b671c0366eb290919719fa56c0e ("resolv: Lift domain search list limits [BZ #19569] [BZ #21475]"), where memory allocation was introduced into res_vinit_1. --- resolv/res_init.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Comments
On 21/01/2020 15:41, Florian Weimer wrote: > res_vinit_1 did not close the stream on errors, only on success. > This change moves closing the stream to __resolv_conf_load, for both > the success and error cases. > > Fixes commit 89f187a40fc0ad4e22838526bfe34d73f758b776 ("resolv: Use > getline for configuration file reading in res_vinit_1") and commit > 3f853f22c87f0b671c0366eb290919719fa56c0e ("resolv: Lift domain search > list limits [BZ #19569] [BZ #21475]"), where memory allocation was > introduced into res_vinit_1. > --- > resolv/res_init.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/resolv/res_init.c b/resolv/res_init.c > index 95dce098aa..09345718cd 100644 > --- a/resolv/res_init.c > +++ b/resolv/res_init.c > @@ -508,7 +508,6 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser) > continue; > } > } > - fclose (fp); > } > if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0)) > { > @@ -593,6 +592,13 @@ __resolv_conf_load (struct __res_state *preinit) > } > resolv_conf_parser_free (&parser); > > + if (fp != NULL) > + { > + int saved_errno = errno; > + fclose (fp); > + __set_errno (saved_errno); > + } > + > return conf; > } Why not close the FILE on __resolv_conf_load? It make the FILE object cleanup as close as its creation, which usually improves readability.
* Adhemerval Zanella: > On 21/01/2020 15:41, Florian Weimer wrote: >> res_vinit_1 did not close the stream on errors, only on success. >> This change moves closing the stream to __resolv_conf_load, for both >> the success and error cases. >> >> Fixes commit 89f187a40fc0ad4e22838526bfe34d73f758b776 ("resolv: Use >> getline for configuration file reading in res_vinit_1") and commit >> 3f853f22c87f0b671c0366eb290919719fa56c0e ("resolv: Lift domain search >> list limits [BZ #19569] [BZ #21475]"), where memory allocation was >> introduced into res_vinit_1. >> --- >> resolv/res_init.c | 8 +++++++- >> 1 file changed, 7 insertions(+), 1 deletion(-) >> >> diff --git a/resolv/res_init.c b/resolv/res_init.c >> index 95dce098aa..09345718cd 100644 >> --- a/resolv/res_init.c >> +++ b/resolv/res_init.c >> @@ -508,7 +508,6 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser) >> continue; >> } >> } >> - fclose (fp); >> } >> if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0)) >> { >> @@ -593,6 +592,13 @@ __resolv_conf_load (struct __res_state *preinit) >> } >> resolv_conf_parser_free (&parser); >> >> + if (fp != NULL) >> + { >> + int saved_errno = errno; >> + fclose (fp); >> + __set_errno (saved_errno); >> + } >> + >> return conf; >> } > > Why not close the FILE on __resolv_conf_load? It make the FILE object > cleanup as close as its creation, which usually improves readability. Sorry, I don't understand. Isn't this what the patch does? Thanks, Florian
On 13/02/2020 18:08, Florian Weimer wrote: > * Adhemerval Zanella: > >> On 21/01/2020 15:41, Florian Weimer wrote: >>> res_vinit_1 did not close the stream on errors, only on success. >>> This change moves closing the stream to __resolv_conf_load, for both >>> the success and error cases. >>> >>> Fixes commit 89f187a40fc0ad4e22838526bfe34d73f758b776 ("resolv: Use >>> getline for configuration file reading in res_vinit_1") and commit >>> 3f853f22c87f0b671c0366eb290919719fa56c0e ("resolv: Lift domain search >>> list limits [BZ #19569] [BZ #21475]"), where memory allocation was >>> introduced into res_vinit_1. >>> --- >>> resolv/res_init.c | 8 +++++++- >>> 1 file changed, 7 insertions(+), 1 deletion(-) >>> >>> diff --git a/resolv/res_init.c b/resolv/res_init.c >>> index 95dce098aa..09345718cd 100644 >>> --- a/resolv/res_init.c >>> +++ b/resolv/res_init.c >>> @@ -508,7 +508,6 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser) >>> continue; >>> } >>> } >>> - fclose (fp); >>> } >>> if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0)) >>> { >>> @@ -593,6 +592,13 @@ __resolv_conf_load (struct __res_state *preinit) >>> } >>> resolv_conf_parser_free (&parser); >>> >>> + if (fp != NULL) >>> + { >>> + int saved_errno = errno; >>> + fclose (fp); >>> + __set_errno (saved_errno); >>> + } >>> + >>> return conf; >>> } >> >> Why not close the FILE on __resolv_conf_load? It make the FILE object >> cleanup as close as its creation, which usually improves readability. > > Sorry, I don't understand. Isn't this what the patch does? Nevermind, for some reason I though it was doing on res_vinit_1. LGTM, thanks. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
diff --git a/resolv/res_init.c b/resolv/res_init.c index 95dce098aa..09345718cd 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -508,7 +508,6 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser) continue; } } - fclose (fp); } if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0)) { @@ -593,6 +592,13 @@ __resolv_conf_load (struct __res_state *preinit) } resolv_conf_parser_free (&parser); + if (fp != NULL) + { + int saved_errno = errno; + fclose (fp); + __set_errno (saved_errno); + } + return conf; }