Skip to content

Commit

Permalink
Issue 230 - Initialize fields as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
trink committed Sep 9, 2018
1 parent 0a1ac91 commit 5139405
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(luasandbox VERSION 1.3.1 LANGUAGES C)
project(luasandbox VERSION 1.3.2 LANGUAGES C)

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Generic Lua sandbox for dynamic data analysis")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
Expand Down
8 changes: 5 additions & 3 deletions src/util/heka_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ process_fields(lsb_heka_field *f, const char *p, const char *e)
int wiretype = 0;
long long vi = 0;

memset(f, 0, sizeof(lsb_heka_field));
p = lsb_pb_read_varint(p, e, &vi);
if (!p || vi < 0 || vi > e - p) {
return NULL;
Expand Down Expand Up @@ -291,8 +292,8 @@ bool lsb_decode_heka_message(lsb_heka_message *m,
}
return false;
}
// the new memory will be initialized as needed Issue #231
m->fields = tmp;
memset(&m->fields[m->fields_len], 0, step * sizeof(lsb_heka_field));
}
cp = process_fields(&m->fields[m->fields_len], cp, ep);
++m->fields_len;
Expand Down Expand Up @@ -457,7 +458,8 @@ void lsb_clear_heka_message(lsb_heka_message *m)
lsb_init_const_string(&m->env_version);
lsb_init_const_string(&m->hostname);

if (m->fields) memset(m->fields, 0, m->fields_size * sizeof(lsb_heka_field));
// The fields will be cleared as they are built out anything beyond fields_len
// should be considered uninitialized Issue #231.
m->timestamp = 0;
m->severity = 7;
m->pid = INT_MIN;
Expand All @@ -469,10 +471,10 @@ void lsb_free_heka_message(lsb_heka_message *m)
{
if (!m) return;

lsb_clear_heka_message(m);
free(m->fields);
m->fields = NULL;
m->fields_size = 0;
lsb_clear_heka_message(m);
}


Expand Down

0 comments on commit 5139405

Please sign in to comment.