Merge remote-tracking branch 'origin/fastpath'

* origin/fastpath:
  Fix checking of fwrite return values

Some didn't look quite right so fixed while merging: the return value of
fwrite is in terms of number of objects written, not number of bytes
written and some calls still mixed those up.
This commit is contained in:
Jon Siwek 2014-10-28 15:09:10 -05:00
commit 432744fde4
3 changed files with 12 additions and 9 deletions

View file

@ -1,4 +1,8 @@
2.3-263 | 2014-10-28 15:09:10 -0500
* Fix checking of fwrite return values (Johanna Amann)
2.3-260 | 2014-10-27 12:54:17 -0500 2.3-260 | 2014-10-27 12:54:17 -0500
* Fix errors/warnings when compiling with -std=c++11 (Jon Siwek) * Fix errors/warnings when compiling with -std=c++11 (Jon Siwek)

View file

@ -1 +1 @@
2.3-260 2.3-263

View file

@ -708,10 +708,10 @@ void BroFile::InitEncrypt(const char* keyfile)
secret_len = htonl(secret_len); secret_len = htonl(secret_len);
if ( ! (fwrite("BROENC1", 7, 1, f) && if ( fwrite("BROENC1", 7, 1, f) < 1 ||
fwrite(&secret_len, sizeof(secret_len), 1, f) && fwrite(&secret_len, sizeof(secret_len), 1, f) < 1 ||
fwrite(secret, ntohl(secret_len), 1, f) && fwrite(secret, ntohl(secret_len), 1, f) < 1 ||
fwrite(iv, iv_len, 1, f)) ) fwrite(iv, iv_len, 1, f) < 1 )
{ {
reporter->Error("can't write header to log file %s: %s", reporter->Error("can't write header to log file %s: %s",
name, strerror(errno)); name, strerror(errno));
@ -736,7 +736,7 @@ void BroFile::FinishEncrypt()
int outl; int outl;
EVP_SealFinal(cipher_ctx, cipher_buffer, &outl); EVP_SealFinal(cipher_ctx, cipher_buffer, &outl);
if ( outl && ! fwrite(cipher_buffer, outl, 1, f) ) if ( outl && fwrite(cipher_buffer, outl, 1, f) < 1 )
{ {
reporter->Error("write error for %s: %s", reporter->Error("write error for %s: %s",
name, strerror(errno)); name, strerror(errno));
@ -777,7 +777,7 @@ int BroFile::Write(const char* data, int len)
return 0; return 0;
} }
if ( outl && ! fwrite(cipher_buffer, outl, 1, f) ) if ( outl && fwrite(cipher_buffer, outl, 1, f) < 1 )
{ {
reporter->Error("write error for %s: %s", reporter->Error("write error for %s: %s",
name, strerror(errno)); name, strerror(errno));
@ -792,8 +792,7 @@ int BroFile::Write(const char* data, int len)
return 1; return 1;
} }
len = fwrite(data, 1, len, f); if ( fwrite(data, len, 1, f) < 1 )
if ( len <= 0 )
return false; return false;
if ( rotate_size && current_size < rotate_size && current_size + len >= rotate_size ) if ( rotate_size && current_size < rotate_size && current_size + len >= rotate_size )