[ntp:hackers] Bug in ntp_filegen.c?

Danny Mayer mayer at ntp.isc.org
Tue May 29 02:12:32 PDT 2007


Harlan Stenn wrote:
>> hackers-bounces+terje.mathisen=hda.hydro.com at support.ntp.org wrote:
>>> Folks,
>>>
>>> I have a head cold and I'd appreciate some extra help on this.
>>>
>>> Around ntpd/ntp_filegen.c:393 there is:
>>>
>>>   if (gen->fp != NULL)
>>>      fclose(gen->fp);
>>>
>>> and then around ntpd/ntp_filegen.c:415 there is:
>>>
>>>   if (gen->fp != NULL) {
>>>      ...
>>>   }
>>>
>>> I think this is wrong, or at least sloppy.
>> On the 'belt-and-suspenders' principle I try to always follow such 
>> operations with a set to NULL:
>>
>>    if (gen->fp != NULL) {
>>      fclose(gen->fp);
>>      gen->fp = NULL;
>>    }
>>
>> If I always do that, then I won't crash due to an extra close and/or 
>> attempt to use an already closed handle.
> 
> I committed code to do that earlier tonight.
> 

The one problem with doing that is that it will never execute the code
following the second if statement (line 415) so either that should be
removed, the if statement should be removed or it should use a flag to
conditionally call filegen_setup(). I have no idea what this code is
meant to do so it's hard to know.

Danny


More information about the hackers mailing list