mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Small raw reader fixes
* crash when accessing nonexistant file. * memory leak when reading from file. Addresses #1038.
This commit is contained in:
parent
58290d6fc0
commit
7427ce511b
1 changed files with 15 additions and 8 deletions
|
@ -55,6 +55,13 @@ void Raw::DoClose()
|
||||||
if ( file != 0 )
|
if ( file != 0 )
|
||||||
CloseInput();
|
CloseInput();
|
||||||
|
|
||||||
|
if ( buf != 0 )
|
||||||
|
{
|
||||||
|
// we still have output that has not been flushed. Throw away.
|
||||||
|
delete buf;
|
||||||
|
buf = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( execute && childpid > 0 && kill(childpid, 0) == 0 )
|
if ( execute && childpid > 0 && kill(childpid, 0) == 0 )
|
||||||
{
|
{
|
||||||
// kill child process
|
// kill child process
|
||||||
|
@ -157,13 +164,13 @@ bool Raw::OpenInput()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file = fopen(fname.c_str(), "r");
|
file = fopen(fname.c_str(), "r");
|
||||||
fcntl(fileno(file), F_SETFD, FD_CLOEXEC);
|
|
||||||
if ( ! file )
|
if ( ! file )
|
||||||
{
|
{
|
||||||
Error(Fmt("Init: cannot open %s", fname.c_str()));
|
Error(Fmt("Init: cannot open %s", fname.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fcntl(fileno(file), F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -322,12 +329,14 @@ int64_t Raw::GetLine(FILE* arg_file)
|
||||||
// but first check if we encountered the file end - because if we did this was it.
|
// but first check if we encountered the file end - because if we did this was it.
|
||||||
if ( feof(arg_file) != 0 )
|
if ( feof(arg_file) != 0 )
|
||||||
{
|
{
|
||||||
outbuf = buf;
|
|
||||||
buf = 0;
|
|
||||||
if ( pos == 0 )
|
if ( pos == 0 )
|
||||||
return -1; // signal EOF - and that we had no more data.
|
return -1; // signal EOF - and that we had no more data.
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
outbuf = buf;
|
||||||
|
buf = 0;
|
||||||
return pos;
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repeats++;
|
repeats++;
|
||||||
|
@ -342,15 +351,13 @@ int64_t Raw::GetLine(FILE* arg_file)
|
||||||
{
|
{
|
||||||
outbuf = buf;
|
outbuf = buf;
|
||||||
buf = 0;
|
buf = 0;
|
||||||
buf = new char[block_size];
|
|
||||||
|
|
||||||
|
|
||||||
if ( found < pos )
|
if ( found < pos )
|
||||||
{
|
{
|
||||||
// we have leftovers. copy them into the buffer for the next line
|
// we have leftovers. copy them into the buffer for the next line
|
||||||
buf = new char[block_size];
|
buf = new char[block_size];
|
||||||
memcpy(buf, outbuf + found + sep_length, pos - found - sep_length);
|
memcpy(buf, outbuf + found + sep_length, pos - found - sep_length);
|
||||||
bufpos = pos - found - sep_length;
|
bufpos = pos - found - sep_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
|
@ -368,7 +375,7 @@ int64_t Raw::GetLine(FILE* arg_file)
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalError("Internal control flow execution");
|
InternalError("Internal control flow execution error in raw reader");
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +468,7 @@ bool Raw::DoUpdate()
|
||||||
if ( length == -3 )
|
if ( length == -3 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
else if ( length == -2 || length == -1 )
|
else if ( length == -2 || length == -1 )
|
||||||
// no data ready or eof
|
// no data ready or eof
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue