GH-895: Remove use of Variable-Length-Arrays

This commit is contained in:
Jon Siwek 2020-04-15 16:25:21 -07:00
parent 991501a3d2
commit 15a19414ca
11 changed files with 28 additions and 20 deletions

@ -1 +1 @@
Subproject commit abfe5cb864a17b8c06c70d4674b32a51280ee62b
Subproject commit 5a43a584e861d0fdbcdb42ef848e676dab179bd5

@ -1 +1 @@
Subproject commit 7892be3fb11a458fec2c8879e862f5db987607b2
Subproject commit 105e243ce5ad55ca28f4a6511d18d973d494dd2a

2
cmake

@ -1 +1 @@
Subproject commit aa45717169e44cc171efcf6abf904c5f9725d09a
Subproject commit 3d656738a538a6b3d322a09173b656c929044e2e

View file

@ -308,7 +308,8 @@ DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas, DigestStr* digest
{
// We assume that state ID's don't exceed 10 digits, plus
// we allow one more character for the delimiter.
u_char id_tag[nfas.length() * 11 + 1];
auto id_tag_buf = std::make_unique<u_char[]>(nfas.length() * 11 + 1);
auto id_tag = id_tag_buf.get();
u_char* p = id_tag;
for ( int i = 0; i < nfas.length(); ++i )

View file

@ -565,7 +565,8 @@ int dbg_execute_command(const char* cmd)
delete [] localcmd;
// Make sure we know this op name.
const char* matching_cmds[num_debug_cmds()];
auto matching_cmds_buf = std::make_unique<const char*[]>(num_debug_cmds());
auto matching_cmds = matching_cmds_buf.get();
int num_matches = find_all_matching_cmds(opstring, matching_cmds);
if ( ! num_matches )

View file

@ -27,12 +27,12 @@ refine connection SMB_Conn += {
function uint8s_to_stringval(data: uint8[]): StringVal
%{
int length = data->size();
uint8 buf[length];
auto buf = std::make_unique<uint8[]>(length);
for ( int i = 0; i < length; ++i)
buf[i] = (*data)[i];
const bytestring bs = bytestring(buf, length);
const bytestring bs = bytestring(buf.get(), length);
return utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), bs);
%}
@ -41,7 +41,7 @@ refine connection SMB_Conn += {
if ( s->unicode() == false )
{
int length = s->a()->size();
char buf[length];
auto buf = std::make_unique<char[]>(length);
for ( int i = 0; i < length; i++)
{
@ -52,7 +52,7 @@ refine connection SMB_Conn += {
if ( length > 0 && buf[length-1] == 0x00 )
length--;
return new StringVal(length, buf);
return new StringVal(length, buf.get());
}
else
{

View file

@ -7,14 +7,14 @@ StringVal* array_to_string(vector<uint8> *a);
StringVal* array_to_string(vector<uint8> *a)
{
int len = a->size();
char tmp[len];
char *s = tmp;
auto tmp = std::make_unique<char[]>(len);
char *s = tmp.get();
for ( vector<uint8>::iterator i = a->begin(); i != a->end(); *s++ = *i++ );
while ( len > 0 && tmp[len-1] == '\0' )
--len;
return new StringVal(len, tmp);
return new StringVal(len, tmp.get());
}
%}

View file

@ -51,7 +51,7 @@ void ZIP_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
return;
static unsigned int unzip_size = 4096;
Bytef unzipbuf[unzip_size];
auto unzipbuf = std::make_unique<Bytef[]>(unzip_size);
int allow_restart = 1;
@ -63,7 +63,7 @@ void ZIP_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
while ( true )
{
zip->next_out = unzipbuf;
zip->next_out = unzipbuf.get();
zip->avail_out = unzip_size;
zip_status = inflate(zip, Z_SYNC_FLUSH);
@ -75,7 +75,7 @@ void ZIP_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
int have = unzip_size - zip->avail_out;
if ( have )
ForwardStream(have, unzipbuf, IsOrig());
ForwardStream(have, unzipbuf.get(), IsOrig());
if ( zip_status == Z_STREAM_END )
{

View file

@ -28,8 +28,9 @@ function utf16_bytestring_to_utf8_val(conn: Connection, utf16: bytestring): Stri
// We can't assume that the string data is properly aligned
// here, so make a copy.
UTF16 utf16_copy[utf16.length()]; // Twice as much memory than necessary.
memset(utf16_copy, 0, sizeof(utf16_copy)); // needs to be set to 0, otherwhise we have uninitialized memory issues when utf16.length is odd.
auto utf16_copy_buf = std::make_unique<UTF16[]>(utf16.length()); // Twice as much memory than necessary.
auto utf16_copy = utf16_copy_buf.get();
memset(utf16_copy, 0, sizeof(UTF16) * utf16.length()); // needs to be set to 0, otherwhise we have uninitialized memory issues when utf16.length is odd.
memcpy(utf16_copy, utf16.begin(), utf16.length());
const char* utf16_copy_end = reinterpret_cast<const char*>(utf16_copy) + utf16.length();

View file

@ -1799,7 +1799,10 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info)
// Build file names.
const int buflen = strlen(name) + 128;
char newname[buflen], tmpname[buflen+4];
auto newname_buf = std::make_unique<char[]>(buflen);
auto tmpname_buf = std::make_unique<char[]>(buflen + 4);
auto newname = newname_buf.get();
auto tmpname = tmpname_buf.get();
snprintf(newname, buflen, "%s.%d.%.06f.tmp",
name, getpid(), network_time);

View file

@ -2830,7 +2830,8 @@ function bytestring_to_hexstr%(bytestring: string%): string
%{
bro_uint_t len = bytestring->AsString()->Len();
const u_char* bytes = bytestring->AsString()->Bytes();
char hexstr[(2 * len) + 1];
auto hextr_buf = std::make_unique<char[]>((2 * len) + 1);
auto hexstr = hextr_buf.get();
hexstr[0] = 0;
for ( bro_uint_t i = 0; i < len; ++i )
@ -2861,7 +2862,8 @@ function hexstr_to_bytestring%(hexstr: string%): string
const char* bytes = hexstr->AsString()->CheckString();
int outlen = (len/2);
char bytestring[outlen];
auto bytestring_buf = std::make_unique<char[]>(outlen);
auto bytestring = bytestring_buf.get();
memset(bytestring, 0, outlen);
for ( bro_uint_t i = 0; i < len/2; ++i )