Skip to content

Commit

Permalink
Unirec output: added check of failed array allocation for some conver…
Browse files Browse the repository at this point in the history
…sion functions
  • Loading branch information
havraji6 committed Jun 5, 2020
1 parent 6c0c313 commit 950fcfa
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions extra_plugins/output/unirec/src/translator.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ translate_array_uint(translator_t *trans, const struct translator_rec *rec,
while ((rc = fds_blist_iter_next(&list_it)) == FDS_OK) {
uint64_t value;
void *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);
if (fds_get_uint_be(list_it.field.data, list_it.field.size, &value) != FDS_OK || field_ptr == NULL) {
if (field_ptr == NULL || fds_get_uint_be(list_it.field.data, list_it.field.size, &value) != FDS_OK) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1; // Conversion failed
}
Expand Down Expand Up @@ -595,7 +595,7 @@ translate_array_int(translator_t *trans, const struct translator_rec *rec,
while ((rc = fds_blist_iter_next(&list_it)) == FDS_OK) {
int64_t value;
void *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);
if (fds_get_int_be(list_it.field.data, list_it.field.size, &value) != FDS_OK || field_ptr == NULL) {
if (field_ptr == NULL || fds_get_int_be(list_it.field.data, list_it.field.size, &value) != FDS_OK) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1; // Conversion failed
}
Expand Down Expand Up @@ -625,7 +625,7 @@ translate_array_bool(translator_t *trans, const struct translator_rec *rec,
while ((rc = fds_blist_iter_next(&list_it)) == FDS_OK) {
bool value;
void *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);
if (fds_get_bool(list_it.field.data, list_it.field.size, &value) != FDS_OK || field_ptr == NULL) {
if (field_ptr == NULL || fds_get_bool(list_it.field.data, list_it.field.size, &value) != FDS_OK) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1; // Conversion failed
}
Expand Down Expand Up @@ -655,7 +655,7 @@ translate_array_float(translator_t *trans, const struct translator_rec *rec,
while ((rc = fds_blist_iter_next(&list_it)) == FDS_OK) {
double value;
void *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);
if (fds_get_float_be(list_it.field.data, list_it.field.size, &value) != FDS_OK || field_ptr == NULL) {
if (field_ptr == NULL || fds_get_float_be(list_it.field.data, list_it.field.size, &value) != FDS_OK) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1; // Conversion failed
}
Expand Down Expand Up @@ -685,7 +685,7 @@ translate_array_ip(translator_t *trans, const struct translator_rec *rec,
while ((rc = fds_blist_iter_next(&list_it)) == FDS_OK) {
void *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);

if (translator_store_ip(list_it.field.data, list_it.field.size, field_ptr)) {
if (field_ptr == NULL || translator_store_ip(list_it.field.data, list_it.field.size, field_ptr)) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1;
}
Expand Down Expand Up @@ -713,6 +713,11 @@ translate_array_mac(translator_t *trans, const struct translator_rec *rec,
}

ur_time_t *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);
if (field_ptr == NULL) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1;
}

memcpy(field_ptr, list_it.field.data, 6U);
}

Expand All @@ -735,8 +740,7 @@ translate_array_time(translator_t *trans, const struct translator_rec *rec,
fds_blist_iter_init(&list_it, field, NULL);
while ((rc = fds_blist_iter_next(&list_it)) == FDS_OK) {
ur_time_t *field_ptr = ur_array_append_get_ptr(trans->record.ur_tmplt, trans->record.data, ur_id);

if (translator_store_time(type_ipx, list_it.field.data, list_it.field.size, field_ptr)) {
if (field_ptr == NULL || translator_store_time(type_ipx, list_it.field.data, list_it.field.size, field_ptr)) {
ur_array_clear(trans->record.ur_tmplt, trans->record.data, ur_id);
return 1;
}
Expand Down

0 comments on commit 950fcfa

Please sign in to comment.