[Bro] Is it is a code issue about bro-2.3?

Johanna Amann johanna at icir.org
Tue Oct 28 07:07:02 PDT 2014


Hello Robert,

according to the fwrite manual pages:

"If an error occurs, or the end-of-file is reached, the return value is a
short object count (or zero)."

According to this, checking ferror is unnecessary for fwrites. However you
are right that just checking that the len is 0 is not enough, instead we
should check that the number of bytes written is equal to the number of
bytes we wanted to write, i.e.

if ( fwrite(data, 1, len, f) < len )
  return false;

There are a few more fwrite calls in the file before that, I will give it
a quick pass and submit a patch later today.

Johanna

On Tue, Oct 28, 2014 at 06:55:53AM +0000, Robert_Yang at trendmicro.com.cn wrote:
> Dear,
> 
> BroFile::Write() in src/File.cc,
> 
> len = fwrite(data, 1, len, f);
> if ( len <=0 )
> return false;
> 
> Maybe, the method to check the return value of fwrite is incorrect. We should call ferror to check file operation's result. The following is fixing.
> 
>         len = fwrite(data, 1, len, f);
>         if ( ferror(f) ) {
>              clearerr(f);
>              return false;
>         }
> 
> Would you please verify this question?
> 
> Thanks!
> 
> 
> <table class="TM_EMAIL_NOTICE"><tr><td><pre>
> TREND MICRO EMAIL NOTICE
> The information contained in this email and any attachments is confidential
> and may be subject to copyright or other intellectual property protection.
> If you are not the intended recipient, you are not authorized to use or
> disclose this information, and we request that you notify us by reply mail or
> telephone and delete the original message from your mail system.
> </pre></td></tr></table>

> _______________________________________________
> Bro mailing list
> bro at bro-ids.org
> http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/bro




More information about the Bro mailing list