public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 3/5] resolv: Fix file handle leak in __resolv_conf_load [BZ #25429]
Date: Thu, 13 Feb 2020 21:30:00 -0000	[thread overview]
Message-ID: <d62d1aee-f91f-5fd8-356b-088752f90ac3@linaro.org> (raw)
In-Reply-To: <871rqy5h64.fsf@oldenburg2.str.redhat.com>



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>
 

  reply	other threads:[~2020-02-13 21:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-21 18:41 [PATCH 0/5] Race condition in /etc/resolv.conf reloading (bug 25420) Florian Weimer
2020-01-21 18:41 ` [PATCH 1/5] Add internal <file_change_detection.h> header file Florian Weimer
2020-02-10 19:47   ` Adhemerval Zanella
2020-02-10 19:58     ` Florian Weimer
2020-02-10 20:57       ` Adhemerval Zanella
2020-01-21 18:42 ` [PATCH 4/5] resolv: Enhance __resolv_conf_load to capture file change data Florian Weimer
2020-02-13 21:33   ` Adhemerval Zanella
2020-01-21 18:42 ` [PATCH 2/5] resolv: Use <file_change_detection.h> in __resolv_conf_get_current Florian Weimer
2020-02-13 20:53   ` Adhemerval Zanella
2020-01-21 18:42 ` [PATCH 3/5] resolv: Fix file handle leak in __resolv_conf_load [BZ #25429] Florian Weimer
2020-02-13 21:01   ` Adhemerval Zanella
2020-02-13 21:08     ` Florian Weimer
2020-02-13 21:30       ` Adhemerval Zanella [this message]
2020-01-21 21:28 ` [PATCH 5/5] resolv: Fix ABA race in /etc/resolv.conf change detection [BZ #25420] Florian Weimer
2020-02-13 21:59   ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d62d1aee-f91f-5fd8-356b-088752f90ac3@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).